-
Notifications
You must be signed in to change notification settings - Fork 100
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
Fix channel's payload.data deserialization in RSocketMachine #277
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -784,13 +784,14 @@ class RSocketMachineImpl<D, M> implements RSocketMachine<D, M> { | |
} | ||
|
||
_handleRequestChannel(streamId: number, frame: RequestChannelFrame): void { | ||
const payload = this._deserializePayload(frame); | ||
const existingSubscription = this._subscriptions.get(streamId); | ||
if (existingSubscription) { | ||
//Likely a duplicate REQUEST_CHANNEL frame, ignore per spec | ||
return; | ||
} | ||
|
||
const payloads = new Flowable(subscriber => { | ||
const payloads = new Flowable<Payload<D, M>>(subscriber => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this bug (bug is explained in another code comment) was introduced mainly due to the missing type of this |
||
let firstRequest = true; | ||
|
||
subscriber.onSubscribe({ | ||
|
@@ -823,15 +824,13 @@ class RSocketMachineImpl<D, M> implements RSocketMachine<D, M> { | |
//critically, if n is 0 now, that's okay because we eagerly decremented it | ||
if (firstRequest && n >= 0) { | ||
firstRequest = false; | ||
//release the initial frame we received in frame form due to map operator | ||
subscriber.onNext(frame); | ||
//release the initial payload we received in frame form due to map operator | ||
subscriber.onNext(payload); | ||
} | ||
}, | ||
}); | ||
}, MAX_REQUEST_N); | ||
const framesToPayloads = new FlowableProcessor(payloads, frame => | ||
this._deserializePayload(frame), | ||
); | ||
const framesToPayloads = new FlowableProcessor(payloads); | ||
this._receivers.set(streamId, framesToPayloads); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: |
||
|
||
this._requestHandler.requestChannel(framesToPayloads).subscribe({ | ||
|
@@ -892,13 +891,14 @@ class RSocketMachineImpl<D, M> implements RSocketMachine<D, M> { | |
flags |= FLAGS.COMPLETE; | ||
this._subscriptions.delete(streamId); | ||
} | ||
let metadata; | ||
if (payload.metadata !== undefined && | ||
payload.metadata !== null) { | ||
// eslint-disable-next-line no-bitwise | ||
flags |= FLAGS.METADATA; | ||
metadata = this._serializers.metadata.serialize(payload.metadata); | ||
} | ||
const data = this._serializers.data.serialize(payload.data); | ||
const metadata = this._serializers.metadata.serialize(payload.metadata); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A minor bug fix: don't try to serialize metadata when metadata is not there. serialize it only when it exists. |
||
this._connection.sendOne({ | ||
data, | ||
flags, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all
_handleXXXX
methods, the frame is deserialized first. So in this method also, the payload should be deserialized first, before using it.