title: ScriptUtils.executeSqlScript throws "connection is closed" after spring boot upgrade
body: <p>I was updating spring boot from 2.5.1 to 2.7 together with the r2dbc and postgres dependencies. I did no change the <code>application.yml</code> or test setup. Before the update my repository tests run fine with testcontainers, but now I see this exception which is thrown by a <code>@AfterEach</code> that tries to clean the DB:</p>
  <pre><code>2022-05-29 10:04:52.447  INFO 16673 --- [tainers-r2dbc-0]  [postgres:13.2]                       : Container postgres:13.2 started in PT1.244757S
  
  Failed to execute SQL script statement #1 of InputStream resource [resource loaded through InputStream]: DROP SCHEMA public CASCADE; nested exception is io.r2dbc.postgresql.client.ReactorNettyClient$PostgresConnectionClosedException: Cannot exchange messages because the connection is closed
  org.springframework.r2dbc.connection.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of InputStream resource [resource loaded through InputStream]: DROP SCHEMA public CASCADE; nested exception is io.r2dbc.postgresql.client.ReactorNettyClient$PostgresConnectionClosedException: Cannot exchange messages because the connection is closed
      at org.springframework.r2dbc.connection.init.ScriptUtils.lambda$runStatement$9(ScriptUtils.java:571)
  </code></pre>
  <p>This is my abstract <code>RepositoryTest</code>:</p>
  <pre><code>@DataR2dbcTest
  @ActiveProfiles(&quot;test&quot;)
  internal abstract class RepositoryTest {
    @Autowired
    protected lateinit var connectionFactory: ConnectionFactory
  
    @AfterEach
    fun clean() {
      runSql(
        &quot;&quot;&quot;
        DROP SCHEMA public CASCADE;
        CREATE SCHEMA public;
        &quot;&quot;&quot;
      )
    }
  
    protected fun runSql(sql: String) {
      runScript(InputStreamResource(sql.byteInputStream()))
    }
  
    protected fun runScript(sqlScript: Resource) {
      runBlocking {
        val connection = connectionFactory.create().awaitFirst()
        ScriptUtils.executeSqlScript(connection, sqlScript)
          .block() // &lt;---- throws the said exception, but it worked before the update.
      }
    }
  }
  </code></pre>
  <p>My actual test looks like this:</p>
  <pre><code>internal class MyRepoTest : RepositoryTest() {
    @Autowired
    private lateinit var myRepo: MyRepository
  
    @Test
    fun someTest() {
      val userId = 3429L
      val myEntities = ...
  
      runBlocking { myRepo.saveAll(myEntities).collect() }
  
      val result = myRepo.findAllByUserId(userId).asFlux()
      StepVerifier.create(result)
        .expectNextMatches { it.userId == userId}
        .expectNextMatches { it.userId == userId}
        .verifyComplete()
    }
  }
  </code></pre>
  <p>I guess the way I try to execute the SQL commands is not fine, how should I do it?</p>
  <pre><code>      val connection = connectionFactory.create().awaitFirst()
        ScriptUtils.executeSqlScript(connection, sqlScript)
          .block() // &lt;---- throws the said exception, but it worked before the update.
  </code></pre>
  <p><strong>EDIT</strong></p>
  <p>I figured out that using <code>ResourceDatabasePopulator</code> works fine:</p>
  <pre><code>7protected fun runScript(sqlScript: Resource) {
    runBlocking {
      ResourceDatabasePopulator(sqlScript).populate(connectionFactory).block()
    }
  }
  </code></pre>
  <p>But I still would like to understand why the original implementation now fails.</p>