Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle split frame headers for WebSocket handleMessage #68

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Pass the correct array buffer to dataview when reading framesize (related to [#55](https://github.com/cloudamqp/amqp-client.js/issues/55))
- Raise `AMQPError` when `channelMax` is reached (related to [#43](https://github.com/cloudamqp/amqp-client.js/issues/43))
- Add `Channel#onerror` callback (related to [#40](https://github.com/cloudamqp/amqp-client.js/issues/40))
- Correctly handle frame headers split across reads in the WebSocket client. (related to [#55](https://github.com/cloudamqp/amqp-client.js/issues/55))

### Changed

Expand Down
4 changes: 2 additions & 2 deletions src/amqp-websocket-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export class AMQPWebSocketClient extends AMQPBaseClient {
if (this.frameSize === 0) {
// first 7 bytes of a frame was split over two reads, this reads the second part
if (this.framePos !== 0) {
const len = buf.byteLength - bufPos
this.frameBuffer.set(new Uint8Array(buf, bufPos), this.framePos)
const len = 7 - this.framePos
this.frameBuffer.set(new Uint8Array(buf, bufPos, len), this.framePos)
this.frameSize = new DataView(this.frameBuffer.buffer).getInt32(bufPos + 3) + 8
this.framePos += len
bufPos += len
Expand Down
8 changes: 3 additions & 5 deletions test-browser/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,7 @@ test("can't set too small frameMax", () => {
expect(() => getNewClient({ frameMax: 16 })).toThrow()
})

// TODO: throws unhandled exception, stopping the rest of the test
test.skip("can handle frames split over socket reads", async () => {
test("can handle frames split over socket reads", async () => {
const amqp = getNewClient({ frameMax: 4*1024 })
const conn = await amqp.connect()
const ch = await conn.channel()
Expand All @@ -553,7 +552,7 @@ test.skip("can handle frames split over socket reads", async () => {
const consumer = await q.subscribe({ noAck: true }, () => { if (++i === msgs) consumer.cancel() })
await consumer.wait(20_000)
expect(i).toEqual(msgs)
}, 40_000)
}, 60_000)

test("have to connect socket before opening channels", async () => {
const amqp = getNewClient()
Expand Down Expand Up @@ -635,8 +634,7 @@ test("will split body over multiple frames", async () => {
assert.fail("no msg")
})

// TODO: fails intermittently, throws unhandled exception, stopping the rest of the test
test.skip("can republish in consume block without race condition", async () => {
test("can republish in consume block without race condition", async () => {
const amqp = getNewClient()
const conn = await amqp.connect()
const ch = await conn.channel()
Expand Down