Skip to content

Commit 58d35d6

Browse files
authored
task/s3: handle repeated SIGINT/SIGTERM consistently (#1658)
Noted while working on #1653 When multiple INT/TERM signals are received, the second signal would previously cause unpredictable behaviour: - if the second signal were the same as the first, it would cause immediate exit; - if it was different from the first it would try to shut down ongoing uploads again This commit changes the behaviour to ignore `INT` & `TERM` signals received while shutdown is already in progress.
1 parent 7adcba3 commit 58d35d6

File tree

9 files changed

+207
-195
lines changed

9 files changed

+207
-195
lines changed

lib/task/s3.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@ const uploadPending = withContainer(({ s3, Blobs }) => async (limit) => {
6666
const signals = ['SIGINT', 'SIGTERM'];
6767

6868
let uploader;
69+
let shutdownInProgress;
6970

7071
const shutdownListener = async signal => {
72+
if (shutdownInProgress) {
73+
console.error('Shutdown already in progress.');
74+
return;
75+
}
76+
shutdownInProgress = true;
77+
console.error('Shutting down...');
78+
7179
try {
7280
await s3.destroy();
7381
} catch (err) {
@@ -88,7 +96,7 @@ const uploadPending = withContainer(({ s3, Blobs }) => async (limit) => {
8896

8997
process.kill(process.pid, signal);
9098
};
91-
signals.forEach(s => process.once(s, shutdownListener));
99+
signals.forEach(s => process.on(s, shutdownListener));
92100

93101
try {
94102
console.log(`Uploading ${count ?? 'all'} blobs...`);

test/e2e/s3/test-forms/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/*-attachments/big-*.bin
2+
/5-*.xml
3+
!/5-template.xml
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms" xmlns:odk="http://www.opendatakit.org/xforms">
33
<h:head>
4-
<h:title>Blob Test 5</h:title>
4+
<h:title>Blob Test 5-{{testIdx}}</h:title>
55
<model odk:xforms-version="1.0.0">
66
<itext>
77
<translation lang="default" default="true()">
@@ -12,7 +12,7 @@
1212
</translation>
1313
</itext>
1414
<instance>
15-
<data id="blob_test_5" version="20240506130956">
15+
<data id="blob_test_5_{{testIdx}}" version="20240506130956">
1616
<meta>
1717
<instanceID/>
1818
</meta>

test/e2e/s3/test-forms/6.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<value>Big Bin 1</value>
1010
<value form="image">jr://images/big-1.bin</value>
1111
</text>
12+
<text id="image-big-2-bin">
13+
<value>Big Bin 2</value>
14+
<value form="image">jr://images/big-2.bin</value>
15+
</text>
1216
</translation>
1317
</itext>
1418
<instance>
File renamed without changes.
File renamed without changes.

test/e2e/s3/test-forms/7.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<model odk:xforms-version="1.0.0">
66
<itext>
77
<translation lang="default" default="true()">
8-
<text id="image-big-1-bin">
9-
<value>Big Bin 1</value>
10-
<value form="image">jr://images/big-1.bin</value>
8+
<text id="image-tiny-2-dat">
9+
<value>Tiny Bin 1</value>
10+
<value form="image">jr://images/tiny-1.bin</value>
1111
</text>
12-
<text id="image-big-2-bin">
13-
<value>Big Bin 2</value>
14-
<value form="image">jr://images/big-2.bin</value>
12+
<text id="image-tiny-1-dat">
13+
<value>Tiny Bin 2</value>
14+
<value form="image">jr://images/tiny-2.bin</value>
1515
</text>
1616
</translation>
1717
</itext>

test/e2e/s3/test-forms/8.xml

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)