Opened 12 years ago

Closed 11 years ago

Last modified 10 years ago

#3895 closed defect (fixed)

Cometd: Mutliple callbacks on handler if a user subscribe-unsubscribe-subscribe to a channel.

Reported by: guest Owned by: alex
Priority: high Milestone: 1.2
Component: Dojox Version: 0.9
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by dylan)

If a user subscribes to a channel then unsubscribes and subscribes again, there will be 2 callbacks on the handler when a message is published.

var handler = {

receive: function(obj) {

console.debug("NEW MESSAGE: ", obj.data.message); alert("new message: " + obj.data.message);

}

}

function init() {

dojox.cometd.init(new String(document.location).replace(/http://[^/]*/,'')+"cometd");

}

function subscribe() {

dojox.cometd.subscribe("/messages", handler, "receive");

}

function unsubscribe() {

dojox.cometd.unsubscribe("/messages", handler, "receive");

}

function disconnect() {

dojox.cometd.disconnect();

}

function publish(id) {

dojox.cometd.publish("/messages", {message: document.getElementById(id).value});

}

To reproduce:

init(); subscribe(); publish('test1'); unsubscribe(); subscribe(); publish('test2');

There will be 2 'test2' messages received by the handler. Depending on how many times the user subscribe-unsubscribe, that will be the number of messages(duplicate) that will be received.

Attachments (1)

dojox-cometd-fix.patch (1.9 KB) - added by guest 12 years ago.
dojox.cometd fix patch

Download all attachments as: .zip

Change History (8)

comment:1 Changed 12 years ago by bill

Summary: Mutliple callbacks on handler if a user subscribe-unsubscribe-subscribe to a channel.Cometd: Mutliple callbacks on handler if a user subscribe-unsubscribe-subscribe to a channel.

comment:2 Changed 12 years ago by Tom Trenka

Milestone: 0.9
Owner: changed from Tom Trenka to alex

Changed 12 years ago by guest

Attachment: dojox-cometd-fix.patch added

dojox.cometd fix patch

comment:3 Changed 12 years ago by guest

Hi Alex,

I've attached the fix for this bug.

Cheers, David

dyu@…

comment:4 Changed 12 years ago by gregwilkins

David,

could you improve this patch a little bit:

the topics map probably should be called _topics

the _subscriptions array should be removed and disconnect should iterate the through the values of the _topics map. Actually then _topics could best be called _subscriptions!

Remove the FIXME comment about not doing the unsubscribe properly as it is fixed!

comment:5 Changed 12 years ago by gregwilkins

Also the test in subscribe and unsubscribe for

(useLocalTopics !== true)
(useLocalTopics !== false)

should be

(useLocalTopics !== true)&&(useLocalTopics !== false)

comment:6 Changed 12 years ago by dylan

Milestone: 1.2
Priority: highnormal

comment:7 Changed 11 years ago by dylan

Description: modified (diff)
Resolution: fixed
Status: newclosed

This appears to have been fixed with work Greg did a while back, closing as fixed.

Note: See TracTickets for help on using tickets.