Code 22: Data received on socket was not in the expected format

I’m attempting to use the Node.JS SDK to insert a document into a Couchbase bucket.

The error is ocurring here: https://github.com/scull7/kuss/blob/couchbase/lib/couchbase/wrapper.js#L38

The call initially starts here: https://github.com/scull7/kuss/blob/couchbase/test/lib/couchbase/index.spec.js#L115

Here is my debug output.

  kuss:couchbase:wrapper RUN - Bucket: kuss-test-db, Method: insert, Params: [ 'c0412afe-10ab-47c4-9497-8446eab6658d', { username: 'superman', name_first: 'Clark', name_last: 'Kent', side: 'hero' } ] +0ms
  kuss:couchbase:bucket-pool createNamedPool - Initialize pool named: kuss-test-db +4ms
  kuss:couchbase:bucket-pool Open connection to bucket: kuss-test-db +1ms
  kuss:couchbase:bucket-pool Open connection to bucket: kuss-test-db +8ms
  kuss:couchbase:wrapper RUN - Arguments: [ 'c0412afe-10ab-47c4-9497-8446eab6658d', { username: 'superman', name_first: 'Clark', name_last: 'Kent', side: 'hero' }, [Function: handler] ] +4ms
  kuss:couchbase:wrapper RUN - ERROR: { CouchbaseError message: 'Data received on socket was not in the expected format', code: 22 } +8ms

Anyone have ideas?

Hey @nsculli,

It looks like something is up with the connection to the target node (couchbase://127.0.0.1:11210), these kinds of low-level network error messages are usually due to firewalls or other kinds of network interference. It would also be helpful to see more of the code handling the instantiation of your Couchbase buckets.

Cheers, Brett

Hi @brett19

Thank you for taking a look.

Here is the code that opens the connection to the bucket:

config.url in this case is currently http://localhost, however, I have tried both couchbase:://localhost as well.

Please note that the code is Open Source / MIT, so you can poke around at will. Thank you again for taking time to look through this issue.

Nate

Also, here is the output of my docker ps command

$ docker ps
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                                                                                               NAMES
b89b6eda0f4b        couchbase/server:sandbox   "/entrypoint.sh /o..."   5 days ago          Up 5 days           0.0.0.0:8091-8094->8091-8094/tcp, 11207/tcp, 11211/tcp, 0.0.0.0:11210->11210/tcp, 18091-18093/tcp   couchbase

I am able to view the web UI

Notice that the test bucket kuss-test-db is being created successfully through the SDK as seen here:

Given a locally running, default configured Couchbase instance, and a Node.JS installation, the following steps should re-create the issue:

$ node --version
v7.9.0
$ git clone git@github.com:scull7/kuss.git
$ cd kuss
$ git checkout couchbase
$ DEBUG='kuss:couchbase:*' make test

So… with some strace help from my colleague, we discovered that it an authentication failure. When you create a new bucket through the ClusterManager it has a password automatically set because the authentication type is set to sasl. I’m thinking that a more appropriate error should be thrown.

Right now I’m working updating my code to accommodate per bucket passwords.

Well… nevermind… back to the same error

Here’s the strace output:

connect(14, {sa_family=AF_INET, sin_port=htons(8091), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
epoll_ctl(5, EPOLL_CTL_ADD, 14, {EPOLLOUT, {u32=14, u64=14}}) = 0
epoll_wait(5, [{EPOLLOUT, {u32=14, u64=14}}], 1024, 1956) = 1
getsockopt(14, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
getpeername(14, {sa_family=AF_INET, sin_port=htons(8091), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
getsockname(14, {sa_family=AF_INET, sin_port=htons(56202), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
setsockopt(14, SOL_TCP, TCP_NODELAY, [1], 4) = 0
write(14, "GET /pools/default/bs/kuss-test-db HTTP/1.1\r\nAuthorization: Basic a3Vzcy10ZXN0LWRiOmZvby1iYXI=\r\nHost: localhost:8091\r\nUser-Agent: libcouchbase/2.7.5-njs\r\n\r\n", 156) = 156
epoll_ctl(5, EPOLL_CTL_ADD, 14, {EPOLLIN, {u32=14, u64=14}}) = -1 EEXIST (File exists)
epoll_ctl(5, EPOLL_CTL_MOD, 14, {EPOLLIN, {u32=14, u64=14}}) = 0
epoll_wait(5, [], 1024, 0)              = 0
epoll_wait(5, [{EPOLLIN, {u32=14, u64=14}}], 1024, 1955) = 1
read(14, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nServer: Couchbase Server\r\nPragma: no-cache\r\nDate: Fri, 09 Jun 2017 19:22:20 GMT\r\nContent-Type: application/json; charset=utf-8\r\nCache-Control: no-cache\r\n\r\n3da\r\n{\"rev\":117,\"name\":\"kuss-test-db\",\"uri\":\"/pools/default/buckets/kuss-test-db?bucket_uuid=dc39b1c0e278b330615e930b853e1893\",\"streamingUri\":\"/pools/default/bucketsStreaming/kuss-test-db?bucket_uuid=dc39b1c0e278b330615e930b853e1893\",\"nodes\":[{\"couchApiBase\":\"http://$HOST:8092/kuss-test-db%2Bdc39b1c0e278b330615e930b853e1893\",\"hostname\":\"$HOST:8091\",\"ports\":{\"proxy\":11211,\"direct\":11210}}],\"nodesExt\":[{\"services\":{\"mgmt\":8091,\"indexAdmin\":9100,\"indexScan\":9101,\"indexHttp\":9102,\"indexStreamInit\":9103,\"indexStreamCatchup\":9104,\"indexStreamMaint\":9105,\"capi\":8092,\"projector\":9999,\"kv\":11210,\"moxi\":11211,\"n1ql\":8093},\"thisNode\":true}],\"nodeLocator\":\"vbucket\",\"uuid\":\"dc39b1c0e278b330615e930b853e1893\",\"ddocs\":{\"uri\":\"/pools/default/buckets/kuss-test-db/ddocs\"},\"vBucketServerMap\":{\"hashAlgorithm\":\"CRC\",\"numReplicas\":1,\"serverList\":[\"$HOST:11210\"],\"vBucketMap\":[]},\"bucketCapabilitiesVer\":\"\",\"bucketCapabilities\":[\"cbhello\",\"touch\",\"couchapi\",\"cccp\",\"xdcrCheckpointing\",\"nodesExt\",\"dcp\"]}\r\n", 33211) = 1193
epoll_ctl(5, EPOLL_CTL_ADD, 14, {EPOLLIN, {u32=14, u64=14}}) = -1 EEXIST (File exists)
epoll_ctl(5, EPOLL_CTL_MOD, 14, {EPOLLIN, {u32=14, u64=14}}) = 0
epoll_wait(5, [{EPOLLIN, {u32=14, u64=14}}], 1024, 1945) = 1
read(14, "4\r\n\n\n\n\n\r\n", 33211)    = 9
epoll_ctl(5, EPOLL_CTL_DEL, 14, 0x7fffacf92de0) = 0
close(14)                               = 0
write(2, "Fri, 09 Jun 2017 19:22:20 GMT kuss:couchbase:wrapper RUN - ERROR: { CouchbaseError message: 'Data received on socket was not in the expected format', code: 22 }\n", 161Fri, 09 Jun 2017 19:22:20 GMT kuss:couchbase:wrapper RUN - ERROR: { CouchbaseError message: 'Data received on socket was not in the expected format', code: 22 }

So…

  1. This error appears when there is an auth failure on a bucket.
  2. the sasl authentication with a blank password (the default) does not work.
  3. You will also receive this error if you do not wait some time before attempting to connect to a newly created bucket.