Bulk helper semaphore handling results in hanging await for long-running requests (exceeding flushInterval)
See original GitHub issue🐛 Bug Report
Bulk helper hangs forever when flushInterval is exceeded while iterator is already awaiting semaphore.
To Reproduce
Steps to reproduce the behavior:
- Run below code against a test cluster - should complete successfully
- Simulate long running server-side operation exceeding configured flushInterval. Multiple ways to do this but one way is to modify the compiled Helpers.js with the following:
client.bulk(Object.assign({}, bulkOptions, { body: bulkBody }), reqOptions, async (err, { body }) => {
await new Promise(resolve => setTimeout(resolve, flushInterval));
if (err) return callback(err, null)
- Re-run below code and watch the hanging await caused by onFlushTimeout() invoked on a payload already awaiting semaphore()
Paste your code here:
'use strict'
const util = require("util")
const { Readable } = require('stream');
const { Client } = require('@elastic/elasticsearch');
async function* generator() {
let i = 0
while (i < 10) {
await new Promise(resolve => setTimeout(resolve, 1 * 1000));
yield { i: i++ };
}
};
const readableStream = Readable.from(generator());
const elasticClient = new Client({
[TESTCLUSTER]
});
(async () => {
const bulkHelper = elasticClient.helpers.bulk({
flushBytes: 43,
concurrency: 1,
datasource: readableStream,
onDocument(doc) {
console.log(doc)
return {
index: { _index: 'semaphoretest' }
}
},
onDrop(doc) {
console.log(doc);
}
}).catch((err) => {
console.error(err);
});
while (util.inspect(bulkHelper).includes('pending')) {
await new Promise(resolve => setTimeout(resolve, 1 * 1000));
console.log('...waiting');
}
console.log(await bulkHelper);
})();
Expected behavior
Bulk helper awaits gracefully for queued requests to complete, error, or timeout.
Paste the results here:
{ i: 0 }
...waiting
{ i: 1 }
...waiting
...waiting
...waiting
...[forever]
Your Environment
- node version: v14.17.6
@elastic/elasticsearch
version: >=7.15.0- os: Linux
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Reference Manual: Configuration Parameters - SAP Help Portal
When a user logs off SAP ASE, or when the value of cpu accounting flush interval is exceeded, the accumulated CPU usage statistics...
Read more >Java application using BulkProcessing hangs if elasticsearch ...
Java application hangs after some time and becomes unresponsive. We are indexing data using ... This thread is waiting to acquire semaphore.
Read more >Oracle VM VirtualBox User Manual - Software Download
Welcome to Oracle VM VirtualBox! VirtualBox is a cross-platform virtualization application. What does that mean? For one thing,.
Read more >Oracle VM VirtualBox User Manual
Launching more than 120 VMs on Solaris hosts . ... When dealing with virtualization (and also for understanding the following chapters of ...
Read more >SAP Adaptive Server Enterprise的所有已知BUG列表(1)
cancel command) may result in ASE hang. ... then the new request will wait for the existing request without generating a warning message...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Heya, I wrote this to reproduce the issue:
My observations:
flushInterval
is exactly the same as the server timeout, the third request is never being sentflushInterval
is different from the server timeout (doesn’t matter if higher or lower), the code works as expected.It happens both in v7 and v8. This is weird, we’ll investigate. Thank you for reporting!
(comment to avoid stale)