@remit/sqs-client 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/poller.ts +2 -1
- package/src/producer.test.ts +30 -1
- package/src/producer.ts +5 -0
package/package.json
CHANGED
package/src/poller.ts
CHANGED
|
@@ -231,7 +231,8 @@ const pollTarget = async (
|
|
|
231
231
|
};
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
|
-
*
|
|
234
|
+
* Runs every target's poll loop until one of `signals` is received (default:
|
|
235
|
+
* SIGINT, SIGTERM). The signal aborts each loop's in-flight
|
|
235
236
|
* long-poll receive so an idle worker returns at once instead of waiting out
|
|
236
237
|
* the current 20s poll; a loop mid-handler finishes that handler first. Rejects
|
|
237
238
|
* (crashes the process) if any loop throws — a stuck poller should exit loudly,
|
package/src/producer.test.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import type { AddressInfo } from "node:net";
|
|
2
4
|
import { describe, it } from "node:test";
|
|
3
|
-
import type
|
|
5
|
+
import { ReceiveMessageCommand, type SQSClient } from "@aws-sdk/client-sqs";
|
|
4
6
|
import { AwsQueryProtocol } from "@aws-sdk/core/protocols";
|
|
5
7
|
import { createQueueProducer, isLocalEndpoint } from "./producer.js";
|
|
6
8
|
|
|
@@ -148,3 +150,30 @@ describe("createQueueProducer", () => {
|
|
|
148
150
|
assert.equal((await remote.config.credentials()).accessKeyId, "real");
|
|
149
151
|
});
|
|
150
152
|
});
|
|
153
|
+
|
|
154
|
+
describe("createQueueProducer request timeout", () => {
|
|
155
|
+
it("fails a receive the queue server never answers", async () => {
|
|
156
|
+
const server = createServer(() => {});
|
|
157
|
+
await new Promise<void>((resolve) => {
|
|
158
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
159
|
+
});
|
|
160
|
+
const { port } = server.address() as AddressInfo;
|
|
161
|
+
const queueUrl = `http://127.0.0.1:${port}/000000000000/hung`;
|
|
162
|
+
const client = createQueueProducer({
|
|
163
|
+
queueUrl,
|
|
164
|
+
requestTimeoutMs: 100,
|
|
165
|
+
localCredentials: { accessKeyId: "test", secretAccessKey: "test" },
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
await assert.rejects(
|
|
170
|
+
() => client.send(new ReceiveMessageCommand({ QueueUrl: queueUrl })),
|
|
171
|
+
{ name: "TimeoutError" },
|
|
172
|
+
);
|
|
173
|
+
} finally {
|
|
174
|
+
client.destroy();
|
|
175
|
+
server.closeAllConnections();
|
|
176
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
package/src/producer.ts
CHANGED
|
@@ -12,8 +12,11 @@ export interface CreateQueueProducerOptions {
|
|
|
12
12
|
* sign with and a self-hosted stack has no credential chain to fall back on.
|
|
13
13
|
*/
|
|
14
14
|
readonly localCredentials?: SqsStaticCredentials;
|
|
15
|
+
readonly requestTimeoutMs?: number;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 45_000;
|
|
19
|
+
|
|
17
20
|
const LOOPBACK_HOSTNAMES = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
18
21
|
|
|
19
22
|
/**
|
|
@@ -59,8 +62,10 @@ export const createQueueProducer = (
|
|
|
59
62
|
options: CreateQueueProducerOptions,
|
|
60
63
|
): SQSClient => {
|
|
61
64
|
const { queueUrl, endpoint, env, localCredentials } = options;
|
|
65
|
+
const requestTimeout = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
62
66
|
const local = isLocalEndpoint(queueUrl);
|
|
63
67
|
return new SQSClient({
|
|
68
|
+
requestHandler: { requestTimeout, throwOnRequestTimeout: true },
|
|
64
69
|
endpoint: endpoint ?? (local ? new URL(queueUrl).origin : undefined),
|
|
65
70
|
...(local && { protocol: AwsQueryProtocol }),
|
|
66
71
|
credentials:
|