lascarayf
lascarayf

Reputation: 3733

RESOURCE_EXHAUSTED No session available in the pool

I am using the Spanner client library for Java and i configure the client using Spring.

After a while, the application start to log the following message but i don't understand why. The application concurrency is minimal. It's seem the sessions aren't reused. Any suggestions ?

RESOURCE_EXHAUSTED: No session available in the pool. Maximum number of sessions in the pool can be overridden by invoking SessionPoolOptions#Builder#setMaxSessions. Client can be made to block rather than fail by setting SessionPoolOptions#Builder#setBlockIfPoolExhausted.

@Configuration
public class SpannerConfig {

    @Value("${datasource.instanceId}")
    private String instance;

    @Value("${datasource.databaseId}")
    private String database;

    @Bean
    public Spanner spannerService() throws IOException {

        SessionPoolOptions sessionPoolOptions = SessionPoolOptions.newBuilder()
                .setFailIfPoolExhausted()
                .setMinSessions(5)
                .setMaxSessions(100)
                .build();

        SpannerOptions options = SpannerOptions.newBuilder()
                .setSessionPoolOption(sessionPoolOptions)
                .build();

        return options.getService();
    }


    @Bean
    public DatabaseClient spannerClient(Spanner spannerService) {
        DatabaseId databaseId = DatabaseId.of(spannerService.getOptions().getProjectId(), instance, database);
        return spannerService.getDatabaseClient(databaseId);
    }
}

Upvotes: 0

Views: 1464

Answers (2)

John Corwin
John Corwin

Reputation: 359

It sounds like you have a session leak. Make sure that you're using a try-with-resources expression around any DatabaseClient.singleUse* or DatabaseClient.ReadOnlyTransaction calls to ensure that the Transaction or ResultSet gets closed, allowing the corresponding session to be returned to the session pool.

Upvotes: 2

Martin Zeitler
Martin Zeitler

Reputation: 76649

you are setting .setMaxSessions(100) which obviously does exceed the predefined limit.

in principle, when one client already has allocated 100, the next client can only allocate 0.

the documentation for the sessions reads:

Note: The Cloud Spanner client libraries manage sessions automatically.

... after reading into the source code, I'm sure that the error message is only thrown when using .setFailIfPoolExhausted(). that it reports an exhausted pool, might possibly be a bug, in case StackDriver monitoring tells the opposite.

Upvotes: 0

Related Questions