memcache icon indicating copy to clipboard operation
memcache copied to clipboard

TypeError: setting 'error' on unknown `CLIENT_ERROR bad command line format`

Open cryptojcdenton opened this issue 2 years ago • 2 comments

Hey, been using memcache-client since September in our open-source project, mostly everything has been great so thank you! I've encountered an unusual error that has occurred ~50 times on our servers over the last month, which crashes it due to an uncaught exception.

The stack trace goes like this:

TypeError: Cannot set properties of undefined (setting 'error')
/server/node_modules/memcache-client/dist/lib/connection.js in MemcacheConnection.receiveResult at line 188:32

                retrieve.results[pending.cmdTokens[1]] = {
                    tokens: pending.cmdTokens,
                    casUniq: pending.cmdTokens[4],
                    value: (_a = this.client) === null || _a === void 0 ? void 0 : _a._unpackValue(pending),
                };
            }
            catch (err) {
>>>Exception>>>>           retrieve.error = err;
            }
        }
        delete pending.data;
    }
    shutdown() {
        this._shutdown("Shutdown requested");
    }
/server/node_modules/memcache-parser/dist/lib/memcache-parser.js in MemcacheConnection._copyPending at line 157:26
/server/node_modules/memcache-parser/dist/lib/memcache-parser.js in MemcacheConnection._parseCmd at line 101:29
/server/node_modules/memcache-parser/dist/lib/memcache-parser.js in MemcacheConnection._processData at line 197:25
/server/node_modules/memcache-parser/dist/lib/memcache-parser.js in MemcacheConnection.onData at line 28:25
node:events in Socket.emit at line 514:28
node:domain in Socket.emit at line 488:12
node:internal/streams/readable in addChunk at line 376:12
node:internal/streams/readable in readableAddChunk at line 349:9
node:internal/streams/readable in Readable.push at line 286:10
node:internal/stream_base_commons in TCP.onStreamRead at line 190:23
CLIENT_ERROR bad command line format

It appears that retrieve can be null here: https://github.com/electrode-io/memcache/blob/master/packages/memcache-client/src/lib/connection.ts#L235, when corresponding with CLIENT_ERROR bad command line format. I don't know the specific command that causes this CLIENT_ERROR, but regardless, the memcache client crashes as a whole. Initially I increased maxConnections, as I thought it was some networking error.

Any ideas? Thanks!

Confirmed this error persists on 1.0.5.

cryptojcdenton avatar Nov 07 '23 02:11 cryptojcdenton

There was a command the server rejected with "bad command line format" error. That caused this handler to be invoked, which remove the command from queue https://github.com/electrode-io/memcache/blob/572495967c2d8f2c7253bace89cf02abc7d97edc/packages/memcache-client/src/lib/connection.ts#L257

but then the server responded with more data that no longer has corresponding pending command.

If you can log from the server and find out the command that it rejected, then it'd help to figure out the issue.

jchip avatar Nov 07 '23 17:11 jchip

Confirmed that this error is only appearing on high server load on 1.0.5, when we have a period of hundreds of requests hitting memcached per second. We had a recent spike of traffic and this error happened again after going away for a few days, crashing our server.

Will continue to debug, but it might be some form of concurrency issue since we share a memcache-client across all requests on the server!

cryptojcdenton avatar Nov 10 '23 06:11 cryptojcdenton