testcontainers-java: MSSQL Server throws Prelogin Warning but then works.

i get prelogin warning messages after container boot, but it eventually stops and my sql import script runs just fine. Afterwards the rest of my test runs perfectly, i’d just like to know how i could wait for something or improve this behaviour in anyway.

Aug 06, 2020 9:17:30 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin WARNING: ConnectionID:1 ClientConnectionId: e4e44c35-9473-4c70-ab46-24f526599b5c Prelogin error: host localhost port 32787 Unexpected end of prelogin response after 0 bytes read Aug 06, 2020 9:17:30 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin WARNING: ConnectionID:1 ClientConnectionId: 808607de-dc0c-45b4-bbde-c03e310426d8 Prelogin error: host localhost port 32787 Unexpected end of prelogin response after 0 bytes read Aug 06, 2020 9:17:31 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin WARNING: ConnectionID:1 ClientConnectionId: 6b866882-e0c2-4a93-82d7-5261dc061492 Prelogin error: host localhost port 32787 Unexpected end of prelogin response after 0 bytes read Aug 06, 2020 9:17:31 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin WARNING: ConnectionID:1 ClientConnectionId: d85f4d62-45b0-4b40-b601-a24a2bb3f48e Prelogin error: host localhost port 32787 Unexpected end of prelogin response after 0 bytes read Aug 06, 2020 9:17:32 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin WARNING: ConnectionID:1 ClientConnectionId: 01370df2-2393-4888-8e98-6b2cd8a335e0 Prelogin error: host localhost port 32787 Unexpected end of prelogin response after 0 bytes read Aug 06, 2020 9:17:33 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin WARNING: ConnectionID:1 ClientConnectionId: c57ee0b6-b86c-4a77-a82c-d72e82072595 Prelogin error: host localhost port 32787 Unexpected end of prelogin response after 0 bytes read Aug 06, 2020 9:17:34 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin WARNING: ConnectionID:1 ClientConnectionId: 374d4277-fcd2-4684-a080-ba2c20b91ee7 Prelogin error: host localhost port 32787 Unexpected end of prelogin response after 0 bytes read

This is my extended MssqlContainer, i’ve tried adding a line to wait for a specific log line but it doesn’t seem to make any difference.

public class MyMSSQLContainer extends MSSQLServerContainer<MyMSSQLContainer> {
	private static final String IMAGE_VERSION = "mcr.microsoft.com/mssql/server:2017-CU12";
	private static MyMSSQLContainer container;

	private MyMSSQLContainer() {
		super(IMAGE_VERSION);
	}

	public static MyMSSQLContainer getInstance() {
		if (container == null) {
			container = new MyMSSQLContainer().waitingFor(Wait.forLogMessage("*SQL Server is now ready for client connections*", 1));
		}
		return container;
	}

	@Override
	public void start() {
		super.start();
	}

	@Override
	public void stop() {
		//do nothing, JVM handles shut down
	}
}

This is my base test class where i init the container and run the schema and data init script…

public abstract class AbstractApiTest {
	//for ci testing: https://www.testcontainers.org/supported_docker_environment/continuous_integration/bitbucket_pipelines/
	public static MSSQLServerContainer<MyMSSQLContainer> mssqlServerContainer = MyMSSQLContainer.getInstance();

	@Autowired
	MockMvc mockMvc;

	@Autowired
	ObjectMapper objectMapper;

	static {
		mssqlServerContainer.start();
		ScriptUtils.runInitScript(new JdbcDatabaseDelegate(mssqlServerContainer, ""), "setup.sql");
	}

	static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

		public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
			TestPropertyValues
				.of(
					"spring.datasource.url=" + mssqlServerContainer.getJdbcUrl(),
					"spring.datasource.username=" + mssqlServerContainer.getUsername(),
					"spring.datasource.password=" + mssqlServerContainer.getPassword()
				)
				.applyTo(configurableApplicationContext.getEnvironment());
		}
	}
}

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 8
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Same here with version 1.16.2. A hacky workaround that avoids the warnings in our case:

new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:2017-latest")
      .withStartupCheckStrategy(new MinimumDurationRunningStartupCheckStrategy(Duration.ofSeconds(5)));

As mentioned above, the MS SQL JDBC driver uses the java.util.Logging which, by default, logs to stderr.

To get rid of the noise, you can override the log level:

val logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerConnection")
logger.level = Level.SEVERE

Java:

Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerConnection");
logger.setLevel(Level.SEVERE);

Same issue, but it does not start ever

EDIT: in case someone else also cannot start, I have found a working combination for java 21. Still have the logged errors, but now at least it connects after a few attempts:

                <dependency>
			<groupId>org.testcontainers</groupId>
			<artifactId>mssqlserver</artifactId>
			<version>1.20.2</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>com.microsoft.sqlserver</groupId>
			<artifactId>mssql-jdbc</artifactId>
			<version>12.6.3.jre11</version>
		</dependency>
    @Rule
    public static MSSQLServerContainer mssqlserver = new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:2022-CU15-GDR1-ubuntu-22.04").acceptLicense()
            .waitingFor(Wait.forListeningPort());

    @BeforeAll
    static void init(){
        mssqlserver.start();
        ....
    }