Repository navigation
Error with Datastore Emulator #1331
Description
Activity
How are you telling gcloud-node to talk to the emulator? Can you boil the code down to the smallest parts to reproduce?
- addedapi: datastoreIssues related to the Datastore API.Issues related to the Datastore API.
on May 19, 2016 I just realized that I was importing my projectId as follows:
var dataset = gcloud.datastore({ projectId: process.env.GCLOUD_PROJECT });But hadn't used the command line to specify the value of
GLOUD_PROJECT. It's working now that I've done that.Thanks for being so quick to respond.
Reacted by Harrison Powers and Adilson CarvalhoSo I'm still getting that error when I try to query the Datastore emulator (again, it works on when I deploy using
gcloud). The smallest parts of my code are below:var gcloud = require('gcloud'); var datastore = gcloud.datastore({ projectId: process.env.DATASTORE_PROJECT_ID }); router.get('/', function(req, res) { var clientQuery = datastore.createQuery('Client'); datastore.runQuery(clientQuery, function(err, result) { if(err) res.send(err); else res.send(result); }); });I have also set the following environment variables:
export DATASTORE_PROJECT_ID='projetct-id' export DATASTORE_EMULATOR_HOST=localhost:8080I'm unable to reproduce this one. Using the gcd.sh emulator linked in the docs, I created and started a database:
$ gcd create datastore $ gcd start datastore API endpoint: http://localhost:8080/datastore If you are using a library that supports the DATASTORE_EMULATOR_HOST environment variable, run: export DATASTORE_EMULATOR_HOST=localhost:8080I set that env var and ran the script after:
$ export DATASTORE_EMULATOR_HOST=localhost:8080 $ node ./index.jsindex.js:'use strict' var gcloud = require('gcloud') var datastore = gcloud.datastore() var clientQuery = datastore.createQuery('Client') datastore.runQuery(clientQuery, console.log)
GCD output was:
Jun 02, 2016 8:42:37 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete INFO: Adding handler(s) to newly registered Channel. Jun 02, 2016 8:42:37 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead INFO: Detected HTTP/2 connection.Node script output:
null [] { moreResults: 'MORE_RESULTS_AFTER_LIMIT', endCursor: 'CgA=' }I just ran using the basic setup you created, with a small modification: rather than using
gcd, I used./gcd.sh. Besides that everything was the same, but I received the following responses:GCD:
Jun 02, 2016 9:11:55 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete INFO: Adding handler(s) to newly registered Channel. Jun 02, 2016 9:11:55 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead INFO: Detected HTTP/2 connection. Jun 02, 2016 9:11:55 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete INFO: Adding handler(s) to newly registered Channel. Jun 02, 2016 9:11:55 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead INFO: Detected HTTP/2 connection. Jun 02, 2016 9:11:55 AM io.grpc.netty.NettyServerHandler onConnectionError WARNING: Connection Error io.netty.handler.codec.http2.Http2Exception: An existing connection was forcibly closed by the remote host at io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:96) at io.grpc.netty.AbstractNettyHandler.exceptionCaught(AbstractNettyHandler.java:90) at io.netty.channel.ChannelHandlerInvokerUtil.invokeExceptionCaughtNow(ChannelHandlerInvokerUtil.java:64) at io.netty.channel.DefaultChannelHandlerInvoker.invokeExceptionCaught(DefaultChannelHandlerInvoker.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346) at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:131) at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131) at io.netty.channel.ChannelHandlerInvokerUtil.invokeExceptionCaughtNow(ChannelHandlerInvokerUtil.java:64) at io.netty.channel.DefaultChannelHandlerInvoker.invokeExceptionCaught(DefaultChannelHandlerInvoker.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346) at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:131) at io.netty.handler.logging.LoggingHandler.exceptionCaught(LoggingHandler.java:175) at io.netty.channel.ChannelHandlerInvokerUtil.invokeExceptionCaughtNow(ChannelHandlerInvokerUtil.java:64) at io.netty.channel.DefaultChannelHandlerInvoker.invokeExceptionCaught(DefaultChannelHandlerInvoker.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346) at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:131) at io.netty.channel.DefaultChannelPipeline.fireExceptionCaught(DefaultChannelPipeline.java:1066) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.handleReadException(AbstractNioByteChannel.java:87) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:136) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:510) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:467) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:381) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host at sun.nio.ch.SocketDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(Unknown Source) at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) at sun.nio.ch.IOUtil.read(Unknown Source) at sun.nio.ch.SocketChannelImpl.read(Unknown Source) at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288) at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1055) at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:245) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:112) ... 8 more Jun 02, 2016 9:11:55 AM io.grpc.netty.NettyServerTransport notifyTerminated SEVERE: Transport failed io.netty.handler.codec.http2.Http2Exception: An existing connection was forcibly closed by the remote host at io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:96) at io.grpc.netty.AbstractNettyHandler.exceptionCaught(AbstractNettyHandler.java:90) at io.netty.channel.ChannelHandlerInvokerUtil.invokeExceptionCaughtNow(ChannelHandlerInvokerUtil.java:64) at io.netty.channel.DefaultChannelHandlerInvoker.invokeExceptionCaught(DefaultChannelHandlerInvoker.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346) at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:131) at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131) at io.netty.channel.ChannelHandlerInvokerUtil.invokeExceptionCaughtNow(ChannelHandlerInvokerUtil.java:64) at io.netty.channel.DefaultChannelHandlerInvoker.invokeExceptionCaught(DefaultChannelHandlerInvoker.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346) at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:131) at io.netty.handler.logging.LoggingHandler.exceptionCaught(LoggingHandler.java:175) at io.netty.channel.ChannelHandlerInvokerUtil.invokeExceptionCaughtNow(ChannelHandlerInvokerUtil.java:64) at io.netty.channel.DefaultChannelHandlerInvoker.invokeExceptionCaught(DefaultChannelHandlerInvoker.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346) at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:131) at io.netty.channel.DefaultChannelPipeline.fireExceptionCaught(DefaultChannelPipeline.java:1066) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.handleReadException(AbstractNioByteChannel.java:87) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:136) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:510) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:467) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:381) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host at sun.nio.ch.SocketDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(Unknown Source) at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) at sun.nio.ch.IOUtil.read(Unknown Source) at sun.nio.ch.SocketChannelImpl.read(Unknown Source) at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288) at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1055) at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:245) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:112) ... 8 more Jun 02, 2016 9:11:55 AM io.netty.handler.codec.http2.Http2ConnectionHandler processGoAwayWriteResult WARNING: [id: 0x0d559741, L:0.0.0.0/0.0.0.0:8080 ! R:/127.0.0.1:52075] Sending GOAWAY failed: lastStreamId '1', errorCode '2', debugData 'An existing connection was forcibly closed by the remote host'. Forcing shutdown of the connection. java.io.IOException: An existing connection was forcibly closed by the remote host at sun.nio.ch.SocketDispatcher.writev0(Native Method) at sun.nio.ch.SocketDispatcher.writev(Unknown Source) at sun.nio.ch.IOUtil.write(Unknown Source) at sun.nio.ch.SocketChannelImpl.write(Unknown Source) at io.netty.channel.socket.nio.NioSocketChannel.doWrite(NioSocketChannel.java:305) at io.netty.channel.AbstractChannel$AbstractUnsafe.flush0(AbstractChannel.java:839) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.flush0(AbstractNioChannel.java:311) at io.netty.channel.AbstractChannel$AbstractUnsafe.flush(AbstractChannel.java:806) at io.netty.channel.DefaultChannelPipeline$HeadContext.flush(DefaultChannelPipeline.java:1436) at io.netty.channel.ChannelHandlerInvokerUtil.invokeFlushNow(ChannelHandlerInvokerUtil.java:165) at io.netty.channel.DefaultChannelHandlerInvoker.invokeFlush(DefaultChannelHandlerInvoker.java:347) at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:395) at io.netty.channel.AbstractChannelHandlerContext.flush(AbstractChannelHandlerContext.java:259) at io.netty.handler.logging.LoggingHandler.flush(LoggingHandler.java:249) at io.netty.channel.ChannelHandlerInvokerUtil.invokeFlushNow(ChannelHandlerInvokerUtil.java:165) at io.netty.channel.DefaultChannelHandlerInvoker.invokeFlush(DefaultChannelHandlerInvoker.java:347) at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:395) at io.netty.channel.AbstractChannelHandlerContext.flush(AbstractChannelHandlerContext.java:259) at io.netty.channel.ChannelDuplexHandler.flush(ChannelDuplexHandler.java:117) at io.netty.channel.ChannelHandlerInvokerUtil.invokeFlushNow(ChannelHandlerInvokerUtil.java:165) at io.netty.channel.DefaultChannelHandlerInvoker.invokeFlush(DefaultChannelHandlerInvoker.java:347) at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:395) at io.netty.channel.AbstractChannelHandlerContext.flush(AbstractChannelHandlerContext.java:259) at io.netty.handler.codec.http2.Http2ConnectionHandler.onError(Http2ConnectionHandler.java:546) at io.netty.handler.codec.http2.Http2ConnectionHandler.exceptionCaught(Http2ConnectionHandler.java:468) at io.grpc.netty.AbstractNettyHandler.exceptionCaught(AbstractNettyHandler.java:92) at io.netty.channel.ChannelHandlerInvokerUtil.invokeExceptionCaughtNow(ChannelHandlerInvokerUtil.java:64) at io.netty.channel.DefaultChannelHandlerInvoker.invokeExceptionCaught(DefaultChannelHandlerInvoker.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346) at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:131) at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131) at io.netty.channel.ChannelHandlerInvokerUtil.invokeExceptionCaughtNow(ChannelHandlerInvokerUtil.java:64) at io.netty.channel.DefaultChannelHandlerInvoker.invokeExceptionCaught(DefaultChannelHandlerInvoker.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346) at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:131) at io.netty.handler.logging.LoggingHandler.exceptionCaught(LoggingHandler.java:175) at io.netty.channel.ChannelHandlerInvokerUtil.invokeExceptionCaughtNow(ChannelHandlerInvokerUtil.java:64) at io.netty.channel.DefaultChannelHandlerInvoker.invokeExceptionCaught(DefaultChannelHandlerInvoker.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346) at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:131) at io.netty.channel.DefaultChannelPipeline.fireExceptionCaught(DefaultChannelPipeline.java:1066) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.handleReadException(AbstractNioByteChannel.java:87) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:136) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:510) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:467) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:381) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)Node:
E0602 09:11:55.253000000 16496 tcp_client_windows.c:112] on_connect error connec ting to 'ipv6:[::1]:8080': No connection could be made because the target machin e actively refused it. { [Error: Bad Request] code: 400, metadata: Metadata { _internal_repr: {} } }Also, I'm not sure if this matters, but I am running Windows 10 and using Git Bash as my terminal.
Hmm, I'm not sure on this. Let's bring in @pcostell -- should we move this issue over to the datastore repo, or is there something we might be doing here that's improper?
It looks a little bit like the emulator is connecting on ipv4 and then the node client tries to connect with ipv6. Maybe you could try setting the
--hostexplicitly to an IP when you startup the gcd tool and see if that helps?I tried to use the
--hostoption when calling./gcd.sh start, but it said it wasn't a valid option. I then tried./gcd.sh start helpand was shown the following options:$ ./gcd.sh help start start Starts a local Cloud Datastore instance. <directory> must contain a valid datastore project (created using the 'create' action) or be started with --testing. Usage: gcd.sh start [options] [<directory]> Options: -p PORT, --port=PORT The port number to listen to on the local machine. Defaults to port 8080. --testing Start the local Cloud Datastore in 'testing' mode. Equivalent to passing --consistency=1.0 and --store_on_disk=false and --store_index_configuration_on_disk=false. Note that the testing option may mask incorrect assumptions about the consistency of non-ancestor queries; non-ancestor queries are eventually consistent. --allow_remote_shutdown Deprecated --consistency=CONSISTENCY The fraction of job application attempts that will succeed, with 0.0 resulting in no attempts succeeding, and 1.0 resulting in all attempts succeeding. Defaults to 0.9. Note that setting this to 1.0 may mask incorrect assumptions about the consistency of non-ancestor queries; non-ancestor queries are eventually consistent. --store_on_disk=true|false Indicates whether data should stored on disk. When set to false, data is stored in memory only. By default, data is stored on disk in <directory>/WEB-INF/appengine-generated/local_db.bin. --store_index_configuration_on_disk=true|false If this option is not specified or set to true, the presence of the '# AUTOGENERATED' line in <directory>/WEB-INF/index.yaml determines whether indexes will be automatically generated and the index configuration stored on disk. If that file does not exist (such as in new projects created by this tool), indexes will be automatically generated and the configuration stored on disk. Setting this option to false suppresses the creation of the configuration file, regardless of the settings in <directory>/WEB-INF/index.yaml.Ah sorry, you should get the updated emulator, which you can get from gcloud:
gcloud components install cloud-datastore-emulator. This will install it which you can run withgcloud beta emulators datastore start --no-legacy, or you can go run the shell script at$GCLOUD_PATH/platform/cloud-datastore-emulator/cloud_datastore_emulatorOr, we have a direct zip download.
It looks like that uses the old env var,
DATASTORE_LOCAL_HOST-- isDATASTORE_EMULATOR_HOSTdone?@stephenplusplus did you remember to specify
--no-legacywhen running?@pcostell Should I be specifying a local host IP? i.e. 192.168.0.x
13 remaining items
@pcostell After spending a lot of time looking around for help about how to run the emulator locally, I found this issue. I got pretty far but eventually it fails because of a missing class in the jar:
Jun 14, 2016 2:36:06 PM io.grpc.internal.SerializingExecutor$TaskRunner run [datastore] SEVERE: Exception while executing runnable io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$2@5c84cf70 [datastore] java.lang.RuntimeException: java.lang.NoClassDefFoundError: net/sourceforge/yamlbeans/YamlExceptionWhat works: After I found your comment about how to run the emulator with --no-legacy, the emulator comes and definitely gets hit by the requests from a client (same machine) when I set
export DATASTORE_EMULATOR_HOST=localhost:8050However, it looks like perhaps the jar file isn't complete.
thoughts? thanks.
@pcostell Thanks for the update and the pointer to #1368. I replaced the
CloudDatastore.jaringcloud/google-cloud-sdk/platform/gcdand tried to run it with the gcd.sh script. It fails because perhaps the entry point is different in the new version?$ ./gcd.sh start datastore Error: Could not find or load main class com.google.apphosting.client.datastoreservice.tools.CloudDatastoreI tried the "old" way of starting it, but with the new jar file substituted for the original in
gcloud/google-cloud-sdk/platform/cloud-datastore-emulatorand this still suffered from the missing yaml class. Based on your posts, I tried to turn of the yaml parsing with the command line flag--testingbut that is not allowed:$ gcloud beta emulators datastore start --no-legacy --testing usage: gcloud beta emulators datastore start [optional flags] ERROR: (gcloud.beta.emulators.datastore.start) unrecognized arguments: --testingIs there some new invocation parameters needed? Maybe a change to the gcd.sh script in terms of the entry point?
thanks
@iansmith I got it working from the given link; you have to use the
./cloud_datastore_emulatorscript included in the zipfile.➜./cloud_datastore_emulator start --testing Jun 15, 2016 1:55:20 PM com.google.appengine.api.datastore.dev.LocalDatastoreService init INFO: Local Datastore initialized: Type: High Replication Storage: In-memory Jun 15, 2016 1:55:20 PM io.grpc.internal.ManagedChannelImpl <init> INFO: [ManagedChannelImpl@2f943d71] Created with target localhost:8080 Jun 15, 2016 1:55:21 PM io.gapi.emulators.netty.NettyUtil applyJava7LongHostnameWorkaround INFO: Applied Java 7 long hostname workaround. Jun 15, 2016 1:55:21 PM io.netty.channel.DefaultChannelId <clinit> WARNING: -Dio.netty.processId: self (malformed) API endpoint: http://localhost:8080 If you are using a library that supports the DATASTORE_EMULATOR_HOST environment variable, run: export DATASTORE_EMULATOR_HOST=localhost:8080 Dev App Server is now running.Ah, thanks.
I believe this was an issue with the gcloud SDK and has since been fixed in a release. If that's not correct, please let me know if there's something we need to fix in our library.
- added a commit that references this issue
on Feb 25, 2026 - added 2 commits that reference this issue
on Mar 5, 2026 - added a commit that references this issue
on Mar 18, 2026 - added a commit that references this issue
on Mar 27, 2026
After following the instructions in the gcloud documentation, I still can't get the local Datastore emulator working. I've set up a REST API to store data in my Datastore when I receive specific requests. These requests correctly result in storing the data in my Datastore when the application is deployed to Google Cloud, but when I try to perform the same requests locally, I receive the following error:
The command line running the
gcd.shscript is displaying the following when I send the request, but shows no errors:Does anyone have any idea what might be going on?