JSteunou / webstomp-client

Stomp client over websocket for browsers
Apache License 2.0
299 stars 59 forks source link

Subscription to second channel overrides the first subscriber #43

Closed kuceram closed 6 years ago

kuceram commented 7 years ago

This error happens when you send headers object to subscription method like this:

var headers = {'Authorization': `Bearer 123`};
var subscription1 = client.subscribe(destination1, callback1, headers);
var subscription2 = client.subscribe(destination2, callback2, headers);

If you do the second subscription you loose the reference to the first one (callback destination1 is never called). This issue came due to the fact that you break the atomicity rule: https://github.com/JSteunou/webstomp-client/blob/master/src/client.js#L269

You should not manipulate object that are coming from outside.

JSteunou commented 7 years ago

Interesting, I suppose calling subscribe with a clone of headers fix the issue temporary, does it?

kuceram commented 7 years ago

Yes it does. But I would suggest to do a clone internally within the subscribe method as method user might not be aware of this. It is also hard to debug this inconvenient.

JSteunou commented 6 years ago

@kuceram is that ok for you?

kuceram commented 6 years ago

Hi, sorry for late respond. I will check it out as soon as possible and let you know. :-)

kuceram commented 6 years ago

Works fine, now...