@@ -74,23 +74,26 @@ def on_subscription_create(sub_session, sub_details, details=None):
74
74
The handler will then also subscribe on the other router, and when receiving
75
75
events, re-publish those on this router.
76
76
77
- :param sub_id :
77
+ :param sub_session :
78
78
:param sub_details:
79
79
:param details:
80
80
:return:
81
81
"""
82
82
if sub_details ["uri" ].startswith ("wamp." ):
83
83
return
84
84
85
- if sub_details ["id" ] in self ._subs :
86
- # this should not happen actually, but not sure ..
85
+ sub_id = sub_details ["id" ]
86
+
87
+ if sub_id in self ._subs and self ._subs [sub_id ]["sub" ]:
88
+ # This will happen if, partway through the subscription process, the RLink disconnects
87
89
self .log .error ('on_subscription_create: sub ID {sub_id} already in map {method}' ,
88
- sub_id = sub_details [ "id" ] ,
90
+ sub_id = sub_id ,
89
91
method = hltype (BridgeSession ._setup_event_forwarding ))
90
92
return
91
93
92
- self ._subs [sub_details ["id" ]] = sub_details
93
- self ._subs [sub_details ["id" ]]["sub" ] = None
94
+ if sub_id not in self ._subs :
95
+ self ._subs [sub_id ] = sub_details
96
+ self ._subs [sub_id ]["sub" ] = None
94
97
95
98
uri = sub_details ['uri' ]
96
99
ERR_MSG = [None ]
@@ -162,17 +165,17 @@ def on_event(*args, **kwargs):
162
165
uri ))
163
166
return
164
167
165
- if sub_details [ "id" ] not in self ._subs :
168
+ if sub_id not in self ._subs :
166
169
self .log .info ("subscription already gone: {uri}" , uri = sub_details ['uri' ])
167
170
yield sub .unregister ()
168
171
else :
169
- self ._subs [sub_details [ "id" ] ]["sub" ] = sub
172
+ self ._subs [sub_id ]["sub" ] = sub
170
173
171
174
self .log .debug (
172
175
"created forwarding subscription: me={me} other={other} sub_id={sub_id} sub_details={sub_details} details={details} sub_session={sub_session}" ,
173
176
me = self ._session_id ,
174
177
other = other ,
175
- sub_id = sub_details [ "id" ] ,
178
+ sub_id = sub_id ,
176
179
sub_details = sub_details ,
177
180
details = details ,
178
181
sub_session = sub_session ,
@@ -222,12 +225,21 @@ def forward_current_subs():
222
225
def on_remote_join (_session , _details ):
223
226
yield forward_current_subs ()
224
227
228
+ def on_remote_leave (_session , _details ):
229
+ # The remote session has ended, clear subscription records.
230
+ # Clearing this dictionary helps avoid the case where
231
+ # local procedures are not subscribed on the remote leg
232
+ # on reestablishment of remote session.
233
+ # See: https://github.com/crossbario/crossbar/issues/1909
234
+ self ._subs = {}
235
+
225
236
if self .IS_REMOTE_LEG :
226
237
yield forward_current_subs ()
227
238
else :
228
239
# from the local leg, don't try to forward events on the
229
240
# remote leg unless the remote session is established.
230
241
other .on ('join' , on_remote_join )
242
+ other .on ('leave' , on_remote_leave )
231
243
232
244
# listen to when new subscriptions are created on the local router
233
245
yield self .subscribe (on_subscription_create ,
@@ -267,15 +279,18 @@ def on_registration_create(reg_session, reg_details, details=None):
267
279
if reg_details ['uri' ].startswith ("wamp." ):
268
280
return
269
281
270
- if reg_details ['id' ] in self ._regs :
271
- # this should not happen actually, but not sure ..
282
+ reg_id = reg_details ["id" ]
283
+
284
+ if reg_id in self ._regs and self ._regs [reg_id ]["reg" ]:
285
+ # This will happen if, partway through the registration process, the RLink disconnects
272
286
self .log .error ('on_registration_create: reg ID {reg_id} already in map {method}' ,
273
- reg_id = reg_details [ 'id' ] ,
287
+ reg_id = reg_id ,
274
288
method = hltype (BridgeSession ._setup_invocation_forwarding ))
275
289
return
276
290
277
- self ._regs [reg_details ['id' ]] = reg_details
278
- self ._regs [reg_details ['id' ]]['reg' ] = None
291
+ if reg_id not in self ._regs :
292
+ self ._regs [reg_id ] = reg_details
293
+ self ._regs [reg_id ]['reg' ] = None
279
294
280
295
uri = reg_details ['uri' ]
281
296
ERR_MSG = [None ]
@@ -365,17 +380,17 @@ def on_call(*args, **kwargs):
365
380
# on the "other" router, *this* router may have already
366
381
# un-registered. If that happened, our registration will
367
382
# be gone, so we immediately un-register on the other side
368
- if reg_details [ 'id' ] not in self ._regs :
383
+ if reg_id not in self ._regs :
369
384
self .log .info ("registration already gone: {uri}" , uri = reg_details ['uri' ])
370
385
yield reg .unregister ()
371
386
else :
372
- self ._regs [reg_details [ 'id' ] ]['reg' ] = reg
387
+ self ._regs [reg_id ]['reg' ] = reg
373
388
374
- self .log .info (
389
+ self .log .debug (
375
390
"created forwarding registration: me={me} other={other} reg_id={reg_id} reg_details={reg_details} details={details} reg_session={reg_session}" ,
376
391
me = self ._session_id ,
377
392
other = other ._session_id ,
378
- reg_id = reg_details [ 'id' ] ,
393
+ reg_id = reg_id ,
379
394
reg_details = reg_details ,
380
395
details = details ,
381
396
reg_session = reg_session ,
0 commit comments