Skip to content

Operation timeouts do not work as expected #119

Description

@RagnisTS

I've written a small program to demonstrate the problem:

It configures the client's timeout to 1 second and then performs an operation
every 0.5 seconds, each of which is expected to time out.

const memjs = require('memjs');
const net = require('net');

const wait = delay => new Promise(resolve => setTimeout(resolve, delay));
const time = () => (new Date()).getTime();

function getKey(client, key) {
	const start = time();
	return client.get(key).catch(() => {
		// Print how long it took for the operation to return a timeout error
		process.stdout.write(`${key} errored after ${time() - start} ms\n`);
	});
}

async function main() {
	const client = memjs.Client.create('localhost:9999', {
		retries: 0,
		timeout: 1, // timeout configured to 1 second
	});

	getKey(client, 'foo');

	await wait(500);
	getKey(client, 'bar');

	await wait(500);
	getKey(client, 'baz');

	await wait(500);
	getKey(client, 'qux');
}

// Create a TCP server which never responds, so that all operations against it
// will time out.
net.createServer(() => undefined).listen(9999, main);

From the output it's clearly visible that the operations did not time out after
1 second, as was expected. Instead, every new operation caused the previous
one's timeout timer to be reset.

foo errored after 2511 ms
bar errored after 2007 ms
baz errored after 1506 ms
qux errored after 1005 ms

If I keep sending a steady stream of operations every 0.5 seconds, then
none of them will ever time out and the callbacks will be left hanging forever.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions