Skip to content

Spanner API NPE on Java8 GAE Standard #2306

Description

@ifigotin

I'm using Spanner API from Java8 GAE Standard App's http servlet, and when I try to execute a query in response to a GET request, I see the following exception in the logs, after which my request seem to hang

java.lang.NullPointerException
	at com.google.apphosting.runtime.ApiProxyImpl$CurrentRequestThreadFactory.newThread(ApiProxyImpl.java:1267)
	at com.google.common.util.concurrent.ThreadFactoryBuilder$1.newThread(ThreadFactoryBuilder.java:162)
	at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:612)
	at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:925)
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1368)
	at io.grpc.internal.DelayedClientTransport.reprocess(DelayedClientTransport.java:305)
	at io.grpc.internal.ManagedChannelImpl$LbHelperImpl$5.run(ManagedChannelImpl.java:733)
	at io.grpc.internal.ChannelExecutor.drain(ChannelExecutor.java:87)
	at io.grpc.internal.DelayedClientTransport.newStream(DelayedClientTransport.java:185)
	at io.grpc.internal.ClientCallImpl.start(ClientCallImpl.java:222)
	at io.grpc.ForwardingClientCall.start(ForwardingClientCall.java:47)
	at com.google.cloud.spanner.spi.v1.WatchdogInterceptor$MonitoredCall.start(WatchdogInterceptor.java:194)
	at io.grpc.ForwardingClientCall.start(ForwardingClientCall.java:47)
	at com.google.cloud.spanner.spi.v1.SpannerErrorInterceptor$1.start(SpannerErrorInterceptor.java:67)
	at io.grpc.ForwardingClientCall.start(ForwardingClientCall.java:47)
	at com.google.cloud.spanner.spi.v1.GrpcSpannerRpc$MetadataClientCall.start(GrpcSpannerRpc.java:466)
	at io.grpc.stub.ClientCalls.startCall(ClientCalls.java:276)
	at io.grpc.stub.ClientCalls.asyncUnaryRequestCall(ClientCalls.java:252)
	at io.grpc.stub.ClientCalls.futureUnaryCall(ClientCalls.java:186)
	at com.google.cloud.spanner.spi.v1.GrpcSpannerRpc.doUnaryCall(GrpcSpannerRpc.java:430)
	at com.google.cloud.spanner.spi.v1.GrpcSpannerRpc.createSession(GrpcSpannerRpc.java:333)
	at com.google.cloud.spanner.SpannerImpl$2.call(SpannerImpl.java:221)
	at com.google.cloud.spanner.SpannerImpl$2.call(SpannerImpl.java:218)
	at com.google.cloud.spanner.SpannerImpl.runWithRetries(SpannerImpl.java:200)
	at com.google.cloud.spanner.SpannerImpl.createSession(SpannerImpl.java:217)
	at com.google.cloud.spanner.SessionPool$4.run(SessionPool.java:1063)

The test code I'm using is taken from the Spanner examples:

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-spanner</artifactId>
  <version>0.21.1-beta</version>
</dependency>
<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud</artifactId>
  <version>0.21.0-alpha</version>
</dependency>
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.ResultSet;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import com.google.cloud.spanner.Statement;

Sample code within http servlet's doGet method:

      SpannerOptions options = SpannerOptions.newBuilder().build();
      Spanner spanner = options.getService();
      try {
        DatabaseClient dbClient = spanner.getDatabaseClient(DatabaseId.of(
            options.getProjectId(), "spanner123", "xyzdb"));
        // Queries the database
        try (ResultSet resultSet = dbClient.singleUse()
             .executeQuery(Statement.of("SELECT 1"))) {
          while (resultSet.next()) {
            System.out.printf("%d\n\n", resultSet.getLong(0));
          }
        }
      } finally {
        spanner.close();
      }

I believe the exception is thrown within dbClient.singleUse().executeQuery(Statement.of("SELECT 1")) call.

Activity

self-assigned this
on Aug 4, 2017

neozwu commented on Aug 4, 2017

@neozwu
Contributor

This appears to be the same issue as #2150 and #2275 . We are currently working with grpc-java (grpc/grpc-java#3296) to investigate the root cause.

added
priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
on Aug 4, 2017

jabubake commented on Aug 4, 2017

@jabubake
Contributor

@ifigotin : we do have a sample here that works, please let me know if you run into issues with it : https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appengine-java8/spanner

ifigotin commented on Aug 4, 2017

@ifigotin
Author

@jabubake
I tried the example, and after fixing the permissions, it didn't work for me. I.e. my requests just hanged.
I also tried an individual task, 'createDatabase'.

added
api: spannerIssues related to the Spanner API.
type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
on Aug 7, 2017

neozwu commented on Aug 7, 2017

@neozwu
Contributor

This appears to be the same issue as in #2275. I'm closing this one and update the status in #2275.

jabubake commented on Aug 7, 2017

@jabubake
Contributor

@neozwu : this issue was resolved, FYI : Spanner does work fine on App Engine Standard J8

ifigotin commented on Aug 8, 2017

@ifigotin
Author

Regarding the Spanner issue, the issue is not fully resolved yet. At least, the example I tried did not work in standard app engine app (no GAE for businesses). It may be a different issue though, because I don't see the exact exception.

The other example that @jabubake provided did work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the Spanner API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.running on app enginetype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions