Parallel touches get "timeout error"

If I run a Promise.all with some touch functions I get a timeout error. Why?

Test code:

try {
		let upsertPromises = [];
		for(let i = 1; i<=3; i++)  upsertPromises.push(collection.upsert(`test:${i}`, { test: `hi!` }));
		await Promise.all(upsertPromises);

		console.log('series');
		for(let i = 1; i<=3; i++) await collection.touch(`test:${i}`, 500);
		console.log('series ok');

		console.log('parallel');
		let touchPromises = [];
		for(let i = 1; i<=3; i++) touchPromises.push(collection.touch(`test:${i}`, 500));
		await Promise.all(touchPromises);
		console.log('parallel ok');

	} catch(err) {
		console.error(err);
	}

console:

series
series ok
parallel
TimeoutError: timeout
    at _getWrappedErr (node_modules/couchbase/lib/errors.js:816:14)
    at Object.wrapLcbErr (node_modules/couchbase/lib/errors.js:1009:20)
    at node_modules/couchbase/lib/collection.js:850:24 {
  cause: LibcouchbaseError { code: 201 },
  context: KeyValueErrorContext {
    status_code: 4,
    opaque: 7,
    cas: CbCas { '0': <Buffer 00 00 00 00 00 00 00 00> },
    key: 'test:1',
    bucket: 'myBucket',
    collection: '',
    scope: '',
    context: '',
    ref: ''
  }
}

couchbase sdk v3.1.1

1 Like

@losapevo thats because you don’t have await in front of collection.touch. Its an async operation

I was able to reproduce what you were doing and was able to make it work by adding await.

Below is the code

try {
        let upsertPromises = [];
        for(let i = 1; i<=3; i++)  upsertPromises.push(collection.upsert(`test:${i}`, { test: `hi!` }));
        await Promise.all(upsertPromises);

        console.log('series');
        for(let i = 1; i<=3; i++) await collection.touch(`test:${i}`, 500);
        console.log('series ok');

        console.log('parallel');
        let touchPromises = [];
        for(let i = 1; i<=3; i++) touchPromises.push(await collection.touch(`test:${i}`, 500));
        await Promise.all(touchPromises);
        console.log('parallel ok');

    } catch(err) {
        console.error(err);
    }
1 Like

@AV25242 By doing so your are just replicating the first experiment. Putting the await in front of collection.touch force the execution to be in series instead of parallel, and that is not what I want.

I can rearrange the code in a different way, using classic promise instead of using async/await, but I get the same error:

Promise.all([
	collection.upsert(`test:1`, { test: `hi!` }),
	collection.upsert(`test:2`, { test: `hi!` }),
	collection.upsert(`test:3`, { test: `hi!` }),
])
.then(result => {
	console.log('parallel');
	return Promise.all([
		collection.touch(`test:1`, 500),
		collection.touch(`test:2`, 500),
		collection.touch(`test:3`, 500),
	]);
})
.then(result => {
	console.log('parallel ok');
})
.catch(err => {
	console.error(err);
});

Upsert works ok in parallel but touch throws a timeout error

1 Like

Thanks @losapevo let me reach out to the team.

Hi @AV25242 have you heard from the team?

Hey @losapevo,

We are actively looking into this issue. It looks like the issue might be outside of the Node.js SDK specifically, so it may take a bit of time to resolve completely.

Cheers, Brett

1 Like

Hi @brett19 ,
did you guys solved the problem? I’m currently using v3.2.1 and it seems to work fine now

@brett19 @losapevo Do you have a temp solution?

@losapevo Did you experience something like Parent cluster object has been closed - #28 by socketman2016 ?

Hi @socketman2016, for me simply updating the sdk solved the problem. Don’t know if they directly fixed the problem or what. @brett19 said that the issue might be outside the sdk, so maybe the new version of the sdk just uses updated packages that solved the problem

I am using latest SDK