Skip to content

Commit d614d95

Browse files
authored
Do not retry on timeout by default (#2293)
* Do not retry on timeout by default * Stop testing on Node.js 12 No longer available on actions/setup-node * Node.js 14.x is no longer available for testing either * Fix linter issue * Update acceptance tests * Add retryOnTimeout to type defs * Linter cleanup * Drop code coverage step from Github action
1 parent af385f0 commit d614d95

File tree

6 files changed

+132
-146
lines changed

6 files changed

+132
-146
lines changed

.github/workflows/nodejs.yml

Lines changed: 103 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -9,170 +9,136 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: [12.x, 14.x, 16.x]
12+
node-version: [16.x, 18.x, 20.x]
1313
os: [ubuntu-latest, windows-latest, macOS-latest]
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v2
1717

18-
- name: Use Node.js ${{ matrix.node-version }}
19-
uses: actions/setup-node@v1
20-
with:
21-
node-version: ${{ matrix.node-version }}
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: ${{ matrix.node-version }}
2222

23-
- name: Install
24-
run: |
25-
npm install
23+
- name: Install
24+
run: |
25+
npm install
2626
27-
- name: Lint
28-
run: |
29-
npm run lint
27+
- name: Lint
28+
run: |
29+
npm run lint
3030
31-
- name: Unit test
32-
run: |
33-
npm run test:unit
31+
- name: Unit test
32+
run: |
33+
npm run test:unit
3434
35-
- name: Acceptance test
36-
run: |
37-
npm run test:acceptance
35+
- name: Acceptance test
36+
run: |
37+
npm run test:acceptance
3838
39-
- name: Type Definitions
40-
run: |
41-
npm run test:types
39+
- name: Type Definitions
40+
run: |
41+
npm run test:types
4242
4343
helpers-integration-test:
4444
name: Helpers integration test
4545
runs-on: ubuntu-latest
4646

4747
strategy:
4848
matrix:
49-
node-version: [12.x, 14.x, 16.x]
49+
node-version: [16.x, 18.x, 20.x]
5050

5151
steps:
52-
- uses: actions/checkout@v2
52+
- uses: actions/checkout@v2
5353

54-
- name: Configure sysctl limits
55-
run: |
56-
sudo swapoff -a
57-
sudo sysctl -w vm.swappiness=1
58-
sudo sysctl -w fs.file-max=262144
59-
sudo sysctl -w vm.max_map_count=262144
54+
- name: Configure sysctl limits
55+
run: |
56+
sudo swapoff -a
57+
sudo sysctl -w vm.swappiness=1
58+
sudo sysctl -w fs.file-max=262144
59+
sudo sysctl -w vm.max_map_count=262144
6060
61-
- name: Runs Elasticsearch
62-
uses: elastic/elastic-github-actions/elasticsearch@master
63-
with:
64-
stack-version: 7.16-SNAPSHOT
61+
- name: Runs Elasticsearch
62+
uses: elastic/elastic-github-actions/elasticsearch@master
63+
with:
64+
stack-version: 7.16-SNAPSHOT
6565

66-
- name: Use Node.js ${{ matrix.node-version }}
67-
uses: actions/setup-node@v1
68-
with:
69-
node-version: ${{ matrix.node-version }}
66+
- name: Use Node.js ${{ matrix.node-version }}
67+
uses: actions/setup-node@v1
68+
with:
69+
node-version: ${{ matrix.node-version }}
7070

71-
- name: Install
72-
run: |
73-
npm install
71+
- name: Install
72+
run: |
73+
npm install
7474
75-
- name: Integration test
76-
run: |
77-
npm run test:integration:helpers
75+
- name: Integration test
76+
run: |
77+
npm run test:integration:helpers
7878
7979
bundler-support:
8080
name: Bundler support
8181
runs-on: ubuntu-latest
8282

8383
steps:
84-
- uses: actions/checkout@v2
85-
86-
- name: Configure sysctl limits
87-
run: |
88-
sudo swapoff -a
89-
sudo sysctl -w vm.swappiness=1
90-
sudo sysctl -w fs.file-max=262144
91-
sudo sysctl -w vm.max_map_count=262144
92-
93-
- name: Runs Elasticsearch
94-
uses: elastic/elastic-github-actions/elasticsearch@master
95-
with:
96-
stack-version: 7.16-SNAPSHOT
97-
98-
- name: Use Node.js 14.x
99-
uses: actions/setup-node@v1
100-
with:
101-
node-version: 14.x
102-
103-
- name: Install
104-
run: |
105-
npm install
106-
npm install --prefix test/bundlers/parcel-test
107-
npm install --prefix test/bundlers/rollup-test
108-
npm install --prefix test/bundlers/webpack-test
109-
110-
- name: Build
111-
run: |
112-
npm run build --prefix test/bundlers/parcel-test
113-
npm run build --prefix test/bundlers/rollup-test
114-
npm run build --prefix test/bundlers/webpack-test
115-
116-
- name: Run bundle
117-
run: |
118-
npm start --prefix test/bundlers/parcel-test
119-
npm start --prefix test/bundlers/rollup-test
120-
npm start --prefix test/bundlers/webpack-test
84+
- uses: actions/checkout@v2
85+
86+
- name: Configure sysctl limits
87+
run: |
88+
sudo swapoff -a
89+
sudo sysctl -w vm.swappiness=1
90+
sudo sysctl -w fs.file-max=262144
91+
sudo sysctl -w vm.max_map_count=262144
92+
93+
- name: Runs Elasticsearch
94+
uses: elastic/elastic-github-actions/elasticsearch@master
95+
with:
96+
stack-version: 7.16-SNAPSHOT
97+
98+
- name: Use Node.js 14.x
99+
uses: actions/setup-node@v1
100+
with:
101+
node-version: 14.x
102+
103+
- name: Install
104+
run: |
105+
npm install
106+
npm install --prefix test/bundlers/parcel-test
107+
npm install --prefix test/bundlers/rollup-test
108+
npm install --prefix test/bundlers/webpack-test
109+
110+
- name: Build
111+
run: |
112+
npm run build --prefix test/bundlers/parcel-test
113+
npm run build --prefix test/bundlers/rollup-test
114+
npm run build --prefix test/bundlers/webpack-test
115+
116+
- name: Run bundle
117+
run: |
118+
npm start --prefix test/bundlers/parcel-test
119+
npm start --prefix test/bundlers/rollup-test
120+
npm start --prefix test/bundlers/webpack-test
121121
122122
mock-support:
123123
name: Mock support
124124
runs-on: ubuntu-latest
125125

126126
steps:
127-
- uses: actions/checkout@v2
127+
- uses: actions/checkout@v2
128128

129-
- name: Use Node.js 14.x
130-
uses: actions/setup-node@v1
131-
with:
132-
node-version: 14.x
129+
- name: Use Node.js 14.x
130+
uses: actions/setup-node@v1
131+
with:
132+
node-version: 14.x
133133

134-
- name: Install
135-
run: |
136-
npm install
137-
npm install --prefix test/mock
134+
- name: Install
135+
run: |
136+
npm install
137+
npm install --prefix test/mock
138138
139-
- name: Run test
140-
run: |
141-
npm test --prefix test/mock
142-
143-
code-coverage:
144-
name: Code coverage
145-
runs-on: ubuntu-latest
146-
147-
strategy:
148-
matrix:
149-
node-version: [14.x]
150-
151-
steps:
152-
- uses: actions/checkout@v2
153-
154-
- name: Use Node.js ${{ matrix.node-version }}
155-
uses: actions/setup-node@v1
156-
with:
157-
node-version: ${{ matrix.node-version }}
158-
159-
- name: Install
160-
run: |
161-
npm install
162-
163-
- name: Code coverage report
164-
run: |
165-
npm run test:coverage-report
166-
167-
- name: Upload coverage to Codecov
168-
uses: codecov/codecov-action@v1
169-
with:
170-
file: ./coverage.lcov
171-
fail_ci_if_error: true
172-
173-
- name: Code coverage 100%
174-
run: |
175-
npm run test:coverage-100
139+
- name: Run test
140+
run: |
141+
npm test --prefix test/mock
176142
177143
license:
178144
name: License check
@@ -183,17 +149,17 @@ jobs:
183149
node-version: [14.x]
184150

185151
steps:
186-
- uses: actions/checkout@v2
152+
- uses: actions/checkout@v2
187153

188-
- name: Use Node.js ${{ matrix.node-version }}
189-
uses: actions/setup-node@v1
190-
with:
191-
node-version: ${{ matrix.node-version }}
154+
- name: Use Node.js ${{ matrix.node-version }}
155+
uses: actions/setup-node@v1
156+
with:
157+
node-version: ${{ matrix.node-version }}
192158

193-
- name: Install
194-
run: |
195-
npm install
159+
- name: Install
160+
run: |
161+
npm install
196162
197-
- name: License checker
198-
run: |
199-
npm run license-checker
163+
- name: License checker
164+
run: |
165+
npm run license-checker

lib/Transport.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ interface TransportOptions {
4949
serializer: Serializer;
5050
maxRetries: number;
5151
requestTimeout: number | string;
52+
retryOnTimeout?: boolean;
5253
suggestCompression?: boolean;
5354
compression?: 'gzip';
5455
sniffInterval?: number;

lib/Transport.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Transport {
5757
this.serializer = opts.serializer
5858
this.maxRetries = opts.maxRetries
5959
this.requestTimeout = toMs(opts.requestTimeout)
60+
this.retryOnTimeout = opts.retryOnTimeout != null ? opts.retryOnTimeout : false
6061
this.suggestCompression = opts.suggestCompression === true
6162
this.compression = opts.compression || false
6263
this.context = opts.context || null
@@ -220,6 +221,13 @@ class Transport {
220221
})
221222
}
222223

224+
// do not retry timeout errors by default
225+
if (err.name === 'TimeoutError' && this.retryOnTimeout !== true) {
226+
err.meta = result
227+
this.emit('response', err, result)
228+
return callback(err, result)
229+
}
230+
223231
// retry logic
224232
if (meta.attempts < maxRetries) {
225233
meta.attempts++

test/acceptance/events-order.test.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ test('Connection error', t => {
8888
const client = new Client({
8989
node: 'http://localhost:9200',
9090
Connection: MockConnectionError,
91-
maxRetries: 1
91+
maxRetries: 1,
92+
retryOnTimeout: true
9293
})
9394

9495
const order = [
@@ -124,18 +125,18 @@ test('Connection error', t => {
124125
})
125126

126127
test('TimeoutError error', t => {
127-
t.plan(10)
128+
t.plan(8)
128129

129130
const client = new Client({
130131
node: 'http://localhost:9200',
131132
Connection: MockConnectionTimeout,
132-
maxRetries: 1
133+
maxRetries: 1,
134+
retryOnTimeout: true
133135
})
134136

135137
const order = [
136138
events.SERIALIZATION,
137139
events.REQUEST,
138-
events.REQUEST,
139140
events.RESPONSE
140141
]
141142

@@ -170,7 +171,8 @@ test('RequestAbortedError error', t => {
170171
const client = new Client({
171172
node: 'http://localhost:9200',
172173
Connection: MockConnectionTimeout,
173-
maxRetries: 1
174+
maxRetries: 1,
175+
retryOnTimeout: true
174176
})
175177

176178
const order = [
@@ -221,7 +223,8 @@ test('ResponseError error (no retry)', t => {
221223
const client = new Client({
222224
node: 'http://localhost:9200',
223225
Connection: MockConnection,
224-
maxRetries: 1
226+
maxRetries: 1,
227+
retryOnTimeout: true
225228
})
226229

227230
const order = [
@@ -373,7 +376,8 @@ test('Deserialization Error', t => {
373376
const client = new Client({
374377
node: 'http://localhost:9200',
375378
Connection: MockConnection,
376-
maxRetries: 1
379+
maxRetries: 1,
380+
retryOnTimeout: true
377381
})
378382

379383
const order = [
@@ -423,7 +427,11 @@ test('Socket destroyed while reading the body', t => {
423427
}
424428

425429
buildServer(handler, ({ port }, server) => {
426-
const client = new Client({ node: `http://localhost:${port}`, maxRetries: 1 })
430+
const client = new Client({
431+
node: `http://localhost:${port}`,
432+
maxRetries: 1,
433+
retryOnTimeout: true
434+
})
427435

428436
const order = [
429437
events.SERIALIZATION,

0 commit comments

Comments
 (0)