elasticsearch-js: DeserializationError: Unexpected end of JSON input
š Bug Report
We are making Elasticsearch queries in a test file. The test file has multiple tests, each performing a query. We tried reordering the tests in the file and found that the first test in the file will be the only one that fails. Even with a stripped down body for the query, we are still inconsistently getting the following error:
Text: āDeserializationError: Unexpected end of JSON inputā
To Reproduce
Run the following test multiple times (it takes a variable number of attempts to get the failure):
import { Client } from '@elastic/elasticsearch
const defaultClient = new Client({
node: host,
sniffOnStart: true
})
describe('elastic test', () => {
test('it should not have deserialization errors', async () => {
await defaultClient.search({
index: 'common',
type: '_doc',
body: {
query: {
match_all: {}
}
}
})
})
})
Expected behavior
The test should be passing consistently.
Your Environment
- node version: 10.11.0
@elastic/elasticsearch
version: ^7.5.1- os: Mac
- Elasticsearch instance version: 7.4.2
Please let me know if you need any additional information!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 34 (12 by maintainers)
Iāve been digging this error, and very likely is a connection error in the infrastructure. You are getting the json parsing problem because the client has already started reading the body, but it canāt detect that the socket has failed. For addressing this problem the client needs to check the
Content-Length
header and throw the proper error if the body length does not match. We can try to figure out if the connection has been prematurely closed by combining different events, but I need to check the compatibility of this solution between different Node.js versions.To be clear, the bug is that the client is not signaling the error correctly, but even if it does, the problem is still present out there.
I am facing the exact similar issue from some days now, the configuration is exactly identical and the bug is also the same as well. The JSON response is broken inside the _source field from random places.
Hello! #1343 has landed, it will be available in
7.10
soon šWe originally noticed the error when running tests in a docker container, but I believe we were able to reproduce it in a local node environment with this issueās sample code in āTo Reproduce.ā
Iāll try to do so, @msisti