skip to Main Content

I am trying to insert data into a table in SQL Server hosted on AWS RDS.

It was working fine and suddenly I started getting an issue. It seems like an intermittent issue but I am unable to see why it is this happening

Fail to read any response from the server, the underlying connection might get lost unexpectedly.

This is how I am creating the database connection:

  public static MSSQLPool createMssqlDbPool(Vertx vertx, ConfigModel configModel) {

    MSSQLConnectOptions connectOptions = new MSSQLConnectOptions()
      .setHost(System.getenv().getOrDefault("DB_HOST", configModel.getDbConfig().getHost()))
      .setPort(Integer.parseInt(System.getenv().getOrDefault("DB_PORT", configModel.getDbConfig().getPort())))
      .setDatabase(System.getenv().getOrDefault("DB_NAME", configModel.getDbConfig().getDatabase()))
      .setUser(System.getenv().getOrDefault("DB_USER", configModel.getDbConfig().getUser()))
      .setPassword(System.getenv().getOrDefault("DB_PASSWORD", configModel.getDbConfig().getPassword()));

    // Pool options
    PoolOptions poolOptions = new PoolOptions()
      .setMaxSize(4);

    LOG.info("DB connection : {}", connectOptions.toJson());

    return MSSQLPool.pool(vertx, connectOptions, poolOptions);

  }

I thought the error might be because of version, so i changed the vert.x version from 4.3.8 to 4.4.0.
Now I am getting the error as

io/vertx/sqlclient/ClosedConnectionException

I have read threads on GitHub about adding timeout but they are not definitive.

2

Answers


  1. Chosen as BEST ANSWER

    I found out two solutions.

    • We can reduce the version of mssql-client in vert.x to 4.3.1, which is compatible with the current RDS version of 15.00.4073.23.v1.
    • Alternatively, we can keep the mssql-client version of vert.x at 4.3.8 and upgrade the production database's RDS version to 15.00.4236.7.v1. Compatibility Chart
    Ms-sql Client 4.3.8 RDS(Sql server) 15.00.4236.7.v1
                  4.3.1                 15.00.4073.23.v1
    

  2. If you see this error it is likely a pooled connection has been idle for too long and closed by some intermediate proxy.

    Change your pool options to close idle connections eagerly:

    // Pool options
    PoolOptions poolOptions = new PoolOptions()
      .setMaxSize(4)
      .setIdleTimeout(5)
      .setIdleTimeoutUnit(TimeUnit.MINUTES);
    

    5 minutes is just an example. The longer a connection lives, the better.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search