@imqueue/core 3.7.0 → 3.8.0
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/.claude/settings.local.json +9 -0
- package/CHANGELOG.md +53 -2
- package/package.json +1 -1
- package/src/ClusterManager.d.ts +5 -2
- package/src/ClusteredRedisQueue.d.ts +65 -2
- package/src/ClusteredRedisQueue.js +153 -16
- package/src/IMessageQueue.d.ts +12 -0
- package/src/UDPClusterManager.js +7 -1
- package/src/UDPWorker.d.ts +7 -0
- package/src/UDPWorker.js +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,56 @@ queue does has an entry.
|
|
|
9
9
|
|
|
10
10
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
11
11
|
|
|
12
|
+
## [Unreleased]
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **A broker kept after its announcements lapsed was never checked again, so
|
|
17
|
+
one that later hung stayed in routing until the process restarted.** Since
|
|
18
|
+
3.7.0 a server whose UDP announcements lapse is kept while it answers a
|
|
19
|
+
PING. But the cluster manager reports a lapse once and arms no further
|
|
20
|
+
liveness check, so nothing looked at a kept server again: if its
|
|
21
|
+
announcements never resumed and the broker then stopped answering — its
|
|
22
|
+
connection open and nothing coming back, as with a frozen or partitioned
|
|
23
|
+
host — it kept its share of round-robin and every call routed to it timed
|
|
24
|
+
out. Measured with two brokers at 50 calls/s, one kept and then frozen for
|
|
25
|
+
25 s: 822 calls timed out, and the broker was never removed. Now a kept
|
|
26
|
+
server is asked again at the interval it announced itself at (one second
|
|
27
|
+
by default, never less), for as long as its announcements stay away, and is
|
|
28
|
+
drained and removed the first time it does not answer within
|
|
29
|
+
`IMQ_LAPSED_ANSWER_TIMEOUT`. The same run lost 93 calls, those already sent
|
|
30
|
+
to the broker before it was removed 3 s after it froze. The check stops when
|
|
31
|
+
the server's announcements resume, when it is removed, and on `destroy()`;
|
|
32
|
+
nothing is scheduled for a server whose announcements never lapsed.
|
|
33
|
+
|
|
34
|
+
A lapse means the announcements did not arrive — lost on the network, or
|
|
35
|
+
not sent by the announcer — not that the receiving process was busy:
|
|
36
|
+
holding a service's event loop for 10 s, and stopping its whole process for
|
|
37
|
+
10 s, both kept their brokers with no lapse, since announcements are
|
|
38
|
+
received on the UDP worker thread and datagrams already buffered renew the
|
|
39
|
+
server before its expiry is acted on.
|
|
40
|
+
|
|
41
|
+
### Added
|
|
42
|
+
|
|
43
|
+
- **`IServerInput.timeout`**, how long a server may go unheard, in
|
|
44
|
+
milliseconds, as announced to a discovering cluster manager.
|
|
45
|
+
`UDPClusterManager` sets it from the announcement's interval, static
|
|
46
|
+
`cluster` entries leave it out, and a clustered queue re-checks a server
|
|
47
|
+
kept after its announcements lapsed at that interval (never less than one
|
|
48
|
+
second, and one second where it is missing).
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- **The UDP cluster manager tells a cluster when a server it already has
|
|
53
|
+
announces itself again after a lapse.** Repeat announcements of a known
|
|
54
|
+
server were all withheld from the cluster, so a cluster that kept a lapsed
|
|
55
|
+
server could not learn that its announcements had resumed. With the alive
|
|
56
|
+
check on, the first announcement the manager hears from a server — after a
|
|
57
|
+
lapse, or at all — now reaches the cluster's `add()` even where the cluster
|
|
58
|
+
already has that server; later ones are withheld as before. `add()` is
|
|
59
|
+
idempotent, so a custom cluster sees one extra call per resumption (and one
|
|
60
|
+
at start for a server it was configured with) and nothing else changes.
|
|
61
|
+
|
|
12
62
|
## [3.7.0] - 2026-11-22
|
|
13
63
|
|
|
14
64
|
### Fixed
|
|
@@ -16,8 +66,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
16
66
|
- **A broker whose heartbeats lapsed was dropped while its connections were
|
|
17
67
|
healthy, and the replies it had already delivered were lost.** The UDP
|
|
18
68
|
cluster manager removes a server once it misses its heartbeats for the
|
|
19
|
-
check's timeout. A
|
|
20
|
-
|
|
69
|
+
check's timeout. A lapse means only that the announcements did not arrive —
|
|
70
|
+
lost on the network, or not sent by the announcer — not that the broker is
|
|
71
|
+
gone, and the removal destroyed the server's queue at once: its listeners went
|
|
21
72
|
before its reader was disconnected, so a reply already read was dropped and
|
|
22
73
|
its caller waited out its whole timeout. Now a server removed for lapsed
|
|
23
74
|
heartbeats is asked first; one that answers within
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imqueue/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Fast JSON message queue over Redis for inter-service communication in Node.js & TypeScript microservices — the transport layer of the @imqueue framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"message-queue",
|
package/src/ClusterManager.d.ts
CHANGED
|
@@ -20,13 +20,16 @@ export interface ICluster {
|
|
|
20
20
|
/**
|
|
21
21
|
* Adds a server to the cluster and returns its registration record.
|
|
22
22
|
* Registration is idempotent — an already-known server is returned
|
|
23
|
-
* unchanged.
|
|
23
|
+
* unchanged. A manager calls it again for a known server whose
|
|
24
|
+
* announcements resumed after a lapse, so a cluster still checking that
|
|
25
|
+
* server can stop.
|
|
24
26
|
*/
|
|
25
27
|
add: (server: IServerInput) => IMessageQueueConnection;
|
|
26
28
|
/**
|
|
27
29
|
* Removes a server from the cluster. A no-op when the server is unknown.
|
|
28
30
|
* With `removal.lapsed`, only the server's announcements stopped arriving,
|
|
29
|
-
* and a cluster may keep a server that still answers on its connections
|
|
31
|
+
* and a cluster may keep a server that still answers on its connections —
|
|
32
|
+
* checking it itself until it stops answering or `add` reports it again.
|
|
30
33
|
*/
|
|
31
34
|
remove: (server: IServerInput, removal?: ServerRemoval) => void;
|
|
32
35
|
/**
|
|
@@ -165,6 +165,8 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter<
|
|
|
165
165
|
private readonly waitingSends;
|
|
166
166
|
/** Pending startup shared by batch startup and joining-host initialization. */
|
|
167
167
|
private readonly starting;
|
|
168
|
+
/** Servers kept after their announcements lapsed, while they stay silent. */
|
|
169
|
+
private readonly lapsedWatches;
|
|
168
170
|
/** Membership admission stays closed after the first destroy() call. */
|
|
169
171
|
private closed;
|
|
170
172
|
/** Failed cleanup tasks remain here for an explicit destroy() retry. */
|
|
@@ -611,17 +613,78 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter<
|
|
|
611
613
|
* Removes a server from the cluster, matching by `id` or by host and port.
|
|
612
614
|
*
|
|
613
615
|
* @param server - address of the server to remove
|
|
616
|
+
* @param removal - why it is removed, where the manager can say
|
|
614
617
|
*
|
|
615
618
|
* @remarks
|
|
616
619
|
* A silent no-op when no server matches. Routing stops using the host
|
|
617
620
|
* immediately, but teardown of its redis connections is started in the
|
|
618
|
-
* background and not awaited:
|
|
619
|
-
* and teardown errors are only logged.
|
|
621
|
+
* background and not awaited: what its reader already took is drained to
|
|
622
|
+
* the listeners first, and teardown errors are only logged.
|
|
623
|
+
*
|
|
624
|
+
* With `removal.lapsed` the server is not removed yet: it is asked a PING
|
|
625
|
+
* and kept while it answers within `IMQ_LAPSED_ANSWER_TIMEOUT`, asked
|
|
626
|
+
* again at the interval it announced itself at for as long as its
|
|
627
|
+
* announcements stay away, and removed the first time it does not answer.
|
|
628
|
+
* An `add` for the same server ends that watch.
|
|
620
629
|
*
|
|
621
630
|
* Because the underlying queues are matched by host and port, all entries
|
|
622
631
|
* sharing an address are removed together.
|
|
623
632
|
*/
|
|
624
633
|
protected removeServer(server: IServerInput, removal?: ServerRemoval): void;
|
|
634
|
+
/**
|
|
635
|
+
* Starts watching a server whose announcements lapsed: it is kept while
|
|
636
|
+
* it answers a PING, and dropped the first time it does not.
|
|
637
|
+
*
|
|
638
|
+
* @param server - the removal's address, carrying the interval the server
|
|
639
|
+
* announced itself at where the manager knows it
|
|
640
|
+
* @param imq - the queue serving that server
|
|
641
|
+
*
|
|
642
|
+
* @remarks
|
|
643
|
+
* Once a server is kept, nothing else would look at it again: its cluster
|
|
644
|
+
* manager has already reported the lapse and arms no further liveness
|
|
645
|
+
* check. Without this watch a kept broker that later hung - its socket
|
|
646
|
+
* open, nothing answering - stayed in round-robin until the process
|
|
647
|
+
* restarted, and every call routed to it timed out.
|
|
648
|
+
*
|
|
649
|
+
* A repeated lapse for a server already watched is ignored: the watch in
|
|
650
|
+
* progress already decides it.
|
|
651
|
+
*/
|
|
652
|
+
private watchLapsed;
|
|
653
|
+
/**
|
|
654
|
+
* Asks a lapsed server whether it answers, keeps it and schedules the
|
|
655
|
+
* next check where it does, and drops it where it does not.
|
|
656
|
+
*
|
|
657
|
+
* @param server - the removal's address
|
|
658
|
+
* @param imq - the queue serving that server
|
|
659
|
+
* @param watch - the watch this check belongs to; a check whose watch has
|
|
660
|
+
* ended meanwhile does nothing
|
|
661
|
+
* @param first - whether this is the check made when the lapse was
|
|
662
|
+
* reported, which is the one that logs the server as kept
|
|
663
|
+
*/
|
|
664
|
+
private checkLapsed;
|
|
665
|
+
/**
|
|
666
|
+
* Ends the watch over a lapsed server: its announcements resumed, it is
|
|
667
|
+
* being removed, or the cluster is being destroyed.
|
|
668
|
+
*
|
|
669
|
+
* @param imq - the queue serving that server
|
|
670
|
+
* @returns whether a watch was in progress
|
|
671
|
+
*/
|
|
672
|
+
private cancelLapsed;
|
|
673
|
+
/**
|
|
674
|
+
* How long to wait before asking a kept server again.
|
|
675
|
+
*
|
|
676
|
+
* @param server - the removal's address
|
|
677
|
+
* @returns the interval the server announced itself at, where the
|
|
678
|
+
* removal carries it, but never less than
|
|
679
|
+
* {@link LAPSED_RECHECK_INTERVAL}
|
|
680
|
+
*
|
|
681
|
+
* @remarks
|
|
682
|
+
* The interval is {@link IServerInput.timeout}, which
|
|
683
|
+
* {@link UDPClusterManager} sets from the announcement. A manager that
|
|
684
|
+
* does not set it, or sets a value that is not a positive number, gets
|
|
685
|
+
* the default.
|
|
686
|
+
*/
|
|
687
|
+
private static recheckInterval;
|
|
625
688
|
/**
|
|
626
689
|
* Removes a server known to be gone: out of routing at once, its queue
|
|
627
690
|
* drained of what it already read and then torn down.
|
|
@@ -46,6 +46,26 @@ const SYNC_RETRY_MAX_DELAY = 30000;
|
|
|
46
46
|
* environment variable, defaults to 2,000.
|
|
47
47
|
*/
|
|
48
48
|
const LAPSED_ANSWER_TIMEOUT = envInt('IMQ_LAPSED_ANSWER_TIMEOUT', 2000);
|
|
49
|
+
/**
|
|
50
|
+
* Shortest interval (ms) between two checks of a server kept after its
|
|
51
|
+
* announcements lapsed, and the interval used where the removal does not say
|
|
52
|
+
* how often the server announced itself.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* A kept server is asked again at the interval it announced itself at - the
|
|
56
|
+
* `timeout` a UDP announcement carries, how long its sender may go unheard,
|
|
57
|
+
* which brokers set to their announcement interval (`REDIS_BROADCAST_INTERVAL`,
|
|
58
|
+
* one second by default). The cluster does not know the manager's
|
|
59
|
+
* `aliveTimeoutCorrection`, and does not need it: that correction is slack
|
|
60
|
+
* for datagrams lost on the way, while a PING travels on the connection the
|
|
61
|
+
* queue already holds and carries its own budget,
|
|
62
|
+
* {@link LAPSED_ANSWER_TIMEOUT}. So a broker kept
|
|
63
|
+
* while silent is watched at the cadence its announcements promised, and one
|
|
64
|
+
* that hangs is out of routing within that interval plus the answer budget.
|
|
65
|
+
* The floor keeps a server announcing a zero or tiny interval from turning
|
|
66
|
+
* the check into a PING loop.
|
|
67
|
+
*/
|
|
68
|
+
const LAPSED_RECHECK_INTERVAL = 1000;
|
|
49
69
|
/**
|
|
50
70
|
* Scales a single logical queue horizontally across several redis instances.
|
|
51
71
|
* This is what {@link IMQ.create} returns when {@link IMQOptions.cluster} or
|
|
@@ -156,6 +176,8 @@ export class ClusteredRedisQueue {
|
|
|
156
176
|
waitingSends = new Set();
|
|
157
177
|
/** Pending startup shared by batch startup and joining-host initialization. */
|
|
158
178
|
starting = new WeakMap();
|
|
179
|
+
/** Servers kept after their announcements lapsed, while they stay silent. */
|
|
180
|
+
lapsedWatches = new Map();
|
|
159
181
|
/** Membership admission stays closed after the first destroy() call. */
|
|
160
182
|
closed = false;
|
|
161
183
|
/** Failed cleanup tasks remain here for an explicit destroy() retry. */
|
|
@@ -380,6 +402,7 @@ export class ClusteredRedisQueue {
|
|
|
380
402
|
this.state.started = false;
|
|
381
403
|
for (const imq of this.imqs) {
|
|
382
404
|
this.cancelSync(imq);
|
|
405
|
+
this.cancelLapsed(imq);
|
|
383
406
|
this.cleanup.add(() => imq.destroy());
|
|
384
407
|
}
|
|
385
408
|
for (const manager of this.options.clusterManagers || []) {
|
|
@@ -876,12 +899,19 @@ export class ClusteredRedisQueue {
|
|
|
876
899
|
* Removes a server from the cluster, matching by `id` or by host and port.
|
|
877
900
|
*
|
|
878
901
|
* @param server - address of the server to remove
|
|
902
|
+
* @param removal - why it is removed, where the manager can say
|
|
879
903
|
*
|
|
880
904
|
* @remarks
|
|
881
905
|
* A silent no-op when no server matches. Routing stops using the host
|
|
882
906
|
* immediately, but teardown of its redis connections is started in the
|
|
883
|
-
* background and not awaited:
|
|
884
|
-
* and teardown errors are only logged.
|
|
907
|
+
* background and not awaited: what its reader already took is drained to
|
|
908
|
+
* the listeners first, and teardown errors are only logged.
|
|
909
|
+
*
|
|
910
|
+
* With `removal.lapsed` the server is not removed yet: it is asked a PING
|
|
911
|
+
* and kept while it answers within `IMQ_LAPSED_ANSWER_TIMEOUT`, asked
|
|
912
|
+
* again at the interval it announced itself at for as long as its
|
|
913
|
+
* announcements stay away, and removed the first time it does not answer.
|
|
914
|
+
* An `add` for the same server ends that watch.
|
|
885
915
|
*
|
|
886
916
|
* Because the underlying queues are matched by host and port, all entries
|
|
887
917
|
* sharing an address are removed together.
|
|
@@ -892,24 +922,123 @@ export class ClusteredRedisQueue {
|
|
|
892
922
|
if (!remove) {
|
|
893
923
|
return;
|
|
894
924
|
}
|
|
895
|
-
// only its announcements lapsed
|
|
896
|
-
//
|
|
897
|
-
// asked first,
|
|
925
|
+
// only its announcements lapsed, and a lapse says only that they
|
|
926
|
+
// stopped arriving - lost on the network, or not sent - not that the
|
|
927
|
+
// broker is gone. So the broker is asked first, kept where it still
|
|
928
|
+
// answers, and asked again for as long as it stays silent
|
|
898
929
|
if (removal?.lapsed && remove.imq) {
|
|
899
|
-
|
|
900
|
-
void kept.answers(LAPSED_ANSWER_TIMEOUT).then(answers => {
|
|
901
|
-
if (answers) {
|
|
902
|
-
this.verbose(`Kept the server ${kept.redisKey}: its announcements lapsed, but it answers`);
|
|
903
|
-
return;
|
|
904
|
-
}
|
|
905
|
-
if (this.findServer(server)?.imq === kept) {
|
|
906
|
-
this.dropServer(server);
|
|
907
|
-
}
|
|
908
|
-
});
|
|
930
|
+
this.watchLapsed(server, remove.imq);
|
|
909
931
|
return;
|
|
910
932
|
}
|
|
911
933
|
this.dropServer(server);
|
|
912
934
|
}
|
|
935
|
+
/**
|
|
936
|
+
* Starts watching a server whose announcements lapsed: it is kept while
|
|
937
|
+
* it answers a PING, and dropped the first time it does not.
|
|
938
|
+
*
|
|
939
|
+
* @param server - the removal's address, carrying the interval the server
|
|
940
|
+
* announced itself at where the manager knows it
|
|
941
|
+
* @param imq - the queue serving that server
|
|
942
|
+
*
|
|
943
|
+
* @remarks
|
|
944
|
+
* Once a server is kept, nothing else would look at it again: its cluster
|
|
945
|
+
* manager has already reported the lapse and arms no further liveness
|
|
946
|
+
* check. Without this watch a kept broker that later hung - its socket
|
|
947
|
+
* open, nothing answering - stayed in round-robin until the process
|
|
948
|
+
* restarted, and every call routed to it timed out.
|
|
949
|
+
*
|
|
950
|
+
* A repeated lapse for a server already watched is ignored: the watch in
|
|
951
|
+
* progress already decides it.
|
|
952
|
+
*/
|
|
953
|
+
watchLapsed(server, imq) {
|
|
954
|
+
if (this.closed || this.lapsedWatches.has(imq)) {
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const watch = {};
|
|
958
|
+
this.lapsedWatches.set(imq, watch);
|
|
959
|
+
this.checkLapsed(server, imq, watch, true);
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Asks a lapsed server whether it answers, keeps it and schedules the
|
|
963
|
+
* next check where it does, and drops it where it does not.
|
|
964
|
+
*
|
|
965
|
+
* @param server - the removal's address
|
|
966
|
+
* @param imq - the queue serving that server
|
|
967
|
+
* @param watch - the watch this check belongs to; a check whose watch has
|
|
968
|
+
* ended meanwhile does nothing
|
|
969
|
+
* @param first - whether this is the check made when the lapse was
|
|
970
|
+
* reported, which is the one that logs the server as kept
|
|
971
|
+
*/
|
|
972
|
+
checkLapsed(server, imq, watch, first) {
|
|
973
|
+
void imq.answers(LAPSED_ANSWER_TIMEOUT).then(answers => {
|
|
974
|
+
// announcements resumed, the server was removed or the cluster
|
|
975
|
+
// destroyed while the PING was out: this verdict is no longer
|
|
976
|
+
// anybody's to act on
|
|
977
|
+
if (this.closed || this.lapsedWatches.get(imq) !== watch) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
if (!answers) {
|
|
981
|
+
this.lapsedWatches.delete(imq);
|
|
982
|
+
if (this.findServer(server)?.imq === imq) {
|
|
983
|
+
if (!first) {
|
|
984
|
+
this.verbose(`Removing the server ${imq.redisKey}: kept after its announcements lapsed, it no longer answers`);
|
|
985
|
+
}
|
|
986
|
+
this.dropServer(server);
|
|
987
|
+
}
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
if (first) {
|
|
991
|
+
this.verbose(`Kept the server ${imq.redisKey}: its announcements lapsed, but it answers`);
|
|
992
|
+
}
|
|
993
|
+
const timer = setTimeout(() => {
|
|
994
|
+
watch.timer = undefined;
|
|
995
|
+
if (!this.closed && this.lapsedWatches.get(imq) === watch) {
|
|
996
|
+
this.checkLapsed(server, imq, watch, false);
|
|
997
|
+
}
|
|
998
|
+
}, ClusteredRedisQueue.recheckInterval(server));
|
|
999
|
+
// a kept server must not hold the process open on its own
|
|
1000
|
+
timer.unref?.();
|
|
1001
|
+
watch.timer = timer;
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Ends the watch over a lapsed server: its announcements resumed, it is
|
|
1006
|
+
* being removed, or the cluster is being destroyed.
|
|
1007
|
+
*
|
|
1008
|
+
* @param imq - the queue serving that server
|
|
1009
|
+
* @returns whether a watch was in progress
|
|
1010
|
+
*/
|
|
1011
|
+
cancelLapsed(imq) {
|
|
1012
|
+
const watch = this.lapsedWatches.get(imq);
|
|
1013
|
+
if (!watch) {
|
|
1014
|
+
return false;
|
|
1015
|
+
}
|
|
1016
|
+
clearTimeout(watch.timer);
|
|
1017
|
+
this.lapsedWatches.delete(imq);
|
|
1018
|
+
return true;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* How long to wait before asking a kept server again.
|
|
1022
|
+
*
|
|
1023
|
+
* @param server - the removal's address
|
|
1024
|
+
* @returns the interval the server announced itself at, where the
|
|
1025
|
+
* removal carries it, but never less than
|
|
1026
|
+
* {@link LAPSED_RECHECK_INTERVAL}
|
|
1027
|
+
*
|
|
1028
|
+
* @remarks
|
|
1029
|
+
* The interval is {@link IServerInput.timeout}, which
|
|
1030
|
+
* {@link UDPClusterManager} sets from the announcement. A manager that
|
|
1031
|
+
* does not set it, or sets a value that is not a positive number, gets
|
|
1032
|
+
* the default.
|
|
1033
|
+
*/
|
|
1034
|
+
static recheckInterval(server) {
|
|
1035
|
+
const announced = server.timeout;
|
|
1036
|
+
return announced !== undefined &&
|
|
1037
|
+
Number.isFinite(announced) &&
|
|
1038
|
+
announced > 0
|
|
1039
|
+
? Math.max(LAPSED_RECHECK_INTERVAL, announced)
|
|
1040
|
+
: LAPSED_RECHECK_INTERVAL;
|
|
1041
|
+
}
|
|
913
1042
|
/**
|
|
914
1043
|
* Removes a server known to be gone: out of routing at once, its queue
|
|
915
1044
|
* drained of what it already read and then torn down.
|
|
@@ -923,8 +1052,10 @@ export class ClusteredRedisQueue {
|
|
|
923
1052
|
}
|
|
924
1053
|
const imqToRemove = remove.imq;
|
|
925
1054
|
if (imqToRemove) {
|
|
926
|
-
// a retry scheduled for this host must not
|
|
1055
|
+
// a retry or a lapse check scheduled for this host must not
|
|
1056
|
+
// outlive it
|
|
927
1057
|
this.cancelSync(imqToRemove);
|
|
1058
|
+
this.cancelLapsed(imqToRemove);
|
|
928
1059
|
// dropped from routing first: a catch-up run in progress tests
|
|
929
1060
|
// membership between handlers and stops as soon as it sees this
|
|
930
1061
|
this.imqs = this.imqs.filter(imq => imqToRemove.redisKey !== imq.redisKey);
|
|
@@ -963,6 +1094,12 @@ export class ClusteredRedisQueue {
|
|
|
963
1094
|
}
|
|
964
1095
|
const existingServer = this.findServer(server);
|
|
965
1096
|
if (existingServer) {
|
|
1097
|
+
// a server kept after its announcements lapsed is announcing
|
|
1098
|
+
// itself again: it is back under its manager's liveness check,
|
|
1099
|
+
// and no longer needs this cluster's
|
|
1100
|
+
if (existingServer.imq && this.cancelLapsed(existingServer.imq)) {
|
|
1101
|
+
this.verbose(`Stopped checking the server ${existingServer.imq.redisKey}: its announcements resumed`);
|
|
1102
|
+
}
|
|
966
1103
|
return existingServer;
|
|
967
1104
|
}
|
|
968
1105
|
const newServer = {
|
package/src/IMessageQueue.d.ts
CHANGED
|
@@ -137,6 +137,18 @@ export interface IServerInput {
|
|
|
137
137
|
* TCP port the server listens on.
|
|
138
138
|
*/
|
|
139
139
|
port: number;
|
|
140
|
+
/**
|
|
141
|
+
* How long this server may go unheard, in milliseconds, as announced to a
|
|
142
|
+
* discovering cluster manager — {@link UDPClusterManager} sets it from the
|
|
143
|
+
* interval carried by the server's announcement. Static `cluster` entries
|
|
144
|
+
* leave it out.
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* {@link ClusteredRedisQueue} uses it as the interval at which it asks a
|
|
148
|
+
* server kept after its announcements lapsed whether it still answers,
|
|
149
|
+
* never less than one second, and one second where it is missing.
|
|
150
|
+
*/
|
|
151
|
+
timeout?: number;
|
|
140
152
|
}
|
|
141
153
|
/**
|
|
142
154
|
* A single queue-host endpoint: where to connect and, optionally, how to
|
package/src/UDPClusterManager.js
CHANGED
|
@@ -307,8 +307,14 @@ export class UDPClusterManager extends ClusterManager {
|
|
|
307
307
|
}
|
|
308
308
|
const action = method;
|
|
309
309
|
await this.forEachCluster(cluster => {
|
|
310
|
+
// the worker's announcement, its `timeout` already converted from
|
|
311
|
+
// the wire's seconds to the milliseconds IServerInput declares
|
|
310
312
|
const server = message.server;
|
|
311
|
-
|
|
313
|
+
// a known server is announced again every interval, and only the
|
|
314
|
+
// first announcement after a lapse tells its cluster anything
|
|
315
|
+
if (action === 'add' &&
|
|
316
|
+
message.resumed !== true &&
|
|
317
|
+
cluster.find(server)) {
|
|
312
318
|
return;
|
|
313
319
|
}
|
|
314
320
|
const handler = cluster[action];
|
package/src/UDPWorker.d.ts
CHANGED
|
@@ -89,6 +89,13 @@ export declare class UDPWorker {
|
|
|
89
89
|
* when {@link UDPWorkerOptions.useAliveCheck} is on.
|
|
90
90
|
*
|
|
91
91
|
* @param message - the announcement that named it
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* With the alive check on, the first announcement of a server this worker
|
|
95
|
+
* is not tracking - first heard, or heard again after its announcements
|
|
96
|
+
* lapsed - is marked `resumed`. The manager hands that one to a cluster
|
|
97
|
+
* even where the cluster already has the server: a cluster that kept a
|
|
98
|
+
* lapsed server learns from it that the server announces itself again.
|
|
92
99
|
*/
|
|
93
100
|
private addServer;
|
|
94
101
|
/**
|
package/src/UDPWorker.js
CHANGED
|
@@ -140,11 +140,21 @@ export class UDPWorker {
|
|
|
140
140
|
* when {@link UDPWorkerOptions.useAliveCheck} is on.
|
|
141
141
|
*
|
|
142
142
|
* @param message - the announcement that named it
|
|
143
|
+
*
|
|
144
|
+
* @remarks
|
|
145
|
+
* With the alive check on, the first announcement of a server this worker
|
|
146
|
+
* is not tracking - first heard, or heard again after its announcements
|
|
147
|
+
* lapsed - is marked `resumed`. The manager hands that one to a cluster
|
|
148
|
+
* even where the cluster already has the server: a cluster that kept a
|
|
149
|
+
* lapsed server learns from it that the server announces itself again.
|
|
143
150
|
*/
|
|
144
151
|
addServer(message) {
|
|
152
|
+
const resumed = this.options.useAliveCheck &&
|
|
153
|
+
!this.servers.has(UDPWorker.getServerKey(message));
|
|
145
154
|
this.messagePort.postMessage({
|
|
146
155
|
type: 'cluster:add',
|
|
147
156
|
server: UDPWorker.mapMessage(message),
|
|
157
|
+
...(resumed ? { resumed } : {}),
|
|
148
158
|
});
|
|
149
159
|
if (this.options.useAliveCheck) {
|
|
150
160
|
this.serverAliveWait(message);
|