Open sebekz opened 2 years ago
Hello @sebekz, thanks for opening this. Quick question: are you running from the released NPM package or running from source?
Hey @kavilla. I am running from npm @opensearch-project/opensearch
latest official 1.0.0
build.
Gotcha, right now the latest official build is missing OpenSearchDashboardsClient but I am not positive if its the same issue here: https://github.com/opensearch-project/opensearch-js/issues/181. It got missed in the npm ignore filter.
I am hesitate about diving too deep until that gets officially released. @ananzh, should we prioritize releasing the fix?
@kavilla This is not related to https://github.com/opensearch-project/opensearch-js/issues/181
This is a long-standing bug in the callback handling of Elastic's JavaScript client library. This is an inappropriate destructuring https://github.com/elastic/elasticsearch-js/blob/v7.10.0/lib/Helpers.js#L679 because in the case of an error, you'd expect the first argument to be called with an Error
and the second argument to be null/undefined/unspecified. Destructuring is nice, but it's an overeager use of that feature. This bug has been here since Elastic's introduction of the bulk helper. https://github.com/elastic/elasticsearch-js/commit/51169d5efa3a0194a66c6ec182baa8f916f8833d#diff-84c9e88bdc298227f2ee856382c6f71544b16819981c51aeca0d987a3cc611bcR385
The Elastic client roadmap for v8.0 calls for dropping the callback style completely in favor of supporting only Promises. https://github.com/elastic/elasticsearch-js/issues/1542 Doing that change removed this particular bug vector https://github.com/elastic/elasticsearch-js/commit/1a227459f096951032b881acce18a01352901096#diff-090a51d7c17b7106cfe4dfedac7909f85c0dbc5b79f0f99943c1a76e6ad5ef45L693-R810
A minimal fix would be to move the destructure of body
so that it happens after the code that checks the error and exits with a callback.
Sorry about the delay. Thank you @apostrophest for the details!
Will try to get some prioritization then!
Bump? Running into this issue with client 2.4.0
, Node.js v18.13.0
@curena-contrast Want to pick it up and fix it? At least maybe write a failing test for it?
What is the bug? I am getting an error when trying to use the
client.helpers.bulk
helper.How can one reproduce the bug?
I created an isolated test to illustrate the issue. Hopefully it's easily reproducible this way.
and the result was
Stepping through the code I am able to intercept a single call to
node_modules/@opensearch-project/opensearch/lib/Helpers.js:704:93
whereclient.bulk()
is calledbulkApi()
in\opensearch\api\api\bulk.js
and returns successfullyawait finish()
is called in\opensearch\lib\Helpers.js:559
\opensearch\lib\Transport.js
a call toprepareRequest()
is made, ending withreturn transportReturn
request():177
callingwith
p
beingnull
at that time. That resulted my callback in the AWS Transport class responsible for signing requests to callback to theHelper.js tryBulk()
with second parameter undefined, resulting in theCannot destructure property 'body'
error.What is the expected behavior?
Transport.js
implementation of the request does not result in a nullp
promise issue when callback is passed in therequest() call
What is your host/environment?
Do you have any additional context? Looks to be identical as this SO unresolved issue