amqplib 1.0.2 → 1.0.3
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/CHANGELOG.md +3 -0
- package/lib/mux.js +2 -3
- package/package.json +1 -1
- package/test/mux.test.js +43 -0
- package/.claude/settings.local.json +0 -16
package/CHANGELOG.md
CHANGED
package/lib/mux.js
CHANGED
|
@@ -40,14 +40,13 @@ class Mux {
|
|
|
40
40
|
// Try to read a chunk from each stream in turn, until all streams
|
|
41
41
|
// are empty, or we exhaust our ability to accept chunks.
|
|
42
42
|
function roundrobin(streams) {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
while (accepting && streams.length > 0) {
|
|
44
|
+
const stream = streams.shift();
|
|
45
45
|
const chunk = stream.read();
|
|
46
46
|
if (chunk !== null) {
|
|
47
47
|
accepting = out.write(chunk);
|
|
48
48
|
streams.push(stream);
|
|
49
49
|
}
|
|
50
|
-
stream = streams.shift();
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
package/package.json
CHANGED
package/test/mux.test.js
CHANGED
|
@@ -184,6 +184,49 @@ describe('mux', () => {
|
|
|
184
184
|
});
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
+
it('backpressure does not crash when newStreams is drained', () => {
|
|
188
|
+
// Regression test: out.write() returns false (backpressure) while
|
|
189
|
+
// draining newStreams. The buggy code does an unconditional shift at the
|
|
190
|
+
// bottom of the loop, so if the next stream reads null (empty) it gets
|
|
191
|
+
// discarded without being pushed back, leaving newStreams empty and
|
|
192
|
+
// triggering assert(this.newStreams.length > 0) in the else-branch.
|
|
193
|
+
//
|
|
194
|
+
// Scenario: newStreams = [input1, input2], input1 has data, input2 empty.
|
|
195
|
+
// - shift input1, read 1, write → backpressure (false), push input1 back
|
|
196
|
+
// - (buggy) unconditional shift takes input2, loop condition false → exit
|
|
197
|
+
// - newStreams = [input1], length > 0, assert passes ← not the bug path
|
|
198
|
+
//
|
|
199
|
+
// The crash path requires backpressure AND the shifted stream reading null
|
|
200
|
+
// with no other streams remaining. Use a single stream that has data, then
|
|
201
|
+
// engineer a second read() on the same stream returning null after the
|
|
202
|
+
// write so the stream is not pushed back, emptying newStreams entirely.
|
|
203
|
+
const input1 = stream();
|
|
204
|
+
const output = stream();
|
|
205
|
+
const mux = new Mux(output);
|
|
206
|
+
|
|
207
|
+
mux.newStreams.push(input1);
|
|
208
|
+
input1.write(1);
|
|
209
|
+
|
|
210
|
+
// After the first write (which triggers backpressure), wrap read() so
|
|
211
|
+
// the stream appears empty on the next call — simulating a stream that
|
|
212
|
+
// had one item buffered and is now drained within the same roundrobin pass.
|
|
213
|
+
const originalRead = input1.read.bind(input1);
|
|
214
|
+
let readCount = 0;
|
|
215
|
+
input1.read = (size) => {
|
|
216
|
+
readCount++;
|
|
217
|
+
if (readCount > 1) return null; // appear empty after first read
|
|
218
|
+
return originalRead(size);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const originalWrite = output.write.bind(output);
|
|
222
|
+
output.write = (...args) => {
|
|
223
|
+
originalWrite(...args);
|
|
224
|
+
return false; // signal backpressure immediately
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
assert.doesNotThrow(() => mux._readIncoming());
|
|
228
|
+
});
|
|
229
|
+
|
|
187
230
|
it('roundrobin', (_t, done) => {
|
|
188
231
|
const input1 = stream();
|
|
189
232
|
const input2 = stream();
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Bash(npx oxlint:*)",
|
|
5
|
-
"Bash(npm t)",
|
|
6
|
-
"Bash(git add:*)",
|
|
7
|
-
"Bash(git commit:*)",
|
|
8
|
-
"Bash(npm run lint:*)",
|
|
9
|
-
"Bash(git checkout:*)",
|
|
10
|
-
"Bash(npx biome lint:*)",
|
|
11
|
-
"Bash(node:*)"
|
|
12
|
-
],
|
|
13
|
-
"deny": [],
|
|
14
|
-
"ask": []
|
|
15
|
-
}
|
|
16
|
-
}
|