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

session.publish seem to stuck #39

Closed
aarlt opened this issue Feb 3, 2022 · 4 comments
Closed

session.publish seem to stuck #39

aarlt opened this issue Feb 3, 2022 · 4 comments

Comments

@aarlt
Copy link

aarlt commented Feb 3, 2022

Hello!

I just discovered WAMP & your dart library. First of all, thank you for this great library. I just started to play with it a bit.

However, I'm quite new to dart and maybe the answer to this issue is more related to something that I'm currently not fully understanding. Sorry, if this is the case.

I'm using connectanum-dart v2.0.1.

I wrote the following test program:

import 'dart:async';
import 'dart:io';

import 'package:connectanum/authentication.dart';
import 'package:connectanum/connectanum.dart';
import 'package:connectanum/json.dart';

void main() async {
  final client1 = Client(
    realm: 'test',
    transport: WebSocketTransport(
      'ws://127.0.0.1:8080',
      Serializer(),
      WebSocketSerialization.SERIALIZATION_JSON,
    ),
    authenticationMethods: [CryptosignAuthentication.fromHex('00' * 32)],
  );
  final session1 = await client1.connect().first;
  final subscription = await session1.subscribe(
      '3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29.push');
  subscription.eventStream!.listen(
      (event) => print('received from <id>.push: \'${event.arguments![0]}\''));

  final client2 = Client(
    realm: 'test',
    transport: WebSocketTransport(
      'ws://127.0.0.1:8080',
      Serializer(),
      WebSocketSerialization.SERIALIZATION_JSON,
    ),
    authenticationMethods: [CryptosignAuthentication.fromHex('00' * 32)],
  );
  final session2 = await client2.connect().first;

  await session2.publish(
      '3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29.push',
      arguments: ['Hello']);

  await session2.publish(
      '3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29.push',
      arguments: ['World']);

  unawaited(session1.close());
  unawaited(session2.close());
}

The output right now is

received from <id>.push: 'Hello'

For me it looks like that the program gets stuck within the first await session2.publish. The function session2.publish seem to never return.

Is this behaviour expected? Or did I do something wrong? I expected the program to just publish 'Hello' and 'World'.

Expected output

received from <id>.push: 'Hello'
received from <id>.push: 'World'

Sorry, if this behaviour is somehow related to my quiet limited dart knowledge.

@konsultaner
Copy link
Owner

Hi, great that you like the lib. If your router doesn't send a PUBLISHED message back to the client. Your await will block forever. Could you check your router wether it returns a PUBLISHED or not? If it does return a PUBLISHED this is a bug.

@konsultaner
Copy link
Owner

These are the lines of code:

Future<Published> publish(String topic,
{List<dynamic>? arguments,
Map<String, dynamic>? argumentsKeywords,
PublishOptions? options}) {
var publish = Publish(nextPublishId++, topic,
arguments: arguments,
argumentsKeywords: argumentsKeywords,
options: options);
_transport.send(publish);
var publishStream = _openSessionStreamController.stream.where((message) {
if (message is Published &&
message.publishRequestId == publish.requestId) {
return true;
}
if (message is Error &&
message.requestTypeId == MessageTypes.CODE_PUBLISH &&
message.requestId == publish.requestId) {
throw message;
}
return false;
}).cast<Published>();
return publishStream.first;
}

@aarlt
Copy link
Author

aarlt commented Feb 3, 2022

Hi, great that you like the lib. If your router doesn't send a PUBLISHED message back to the client. Your await will block forever. Could you check your router wether it returns a PUBLISHED or not? If it does return a PUBLISHED this is a bug.

Thanks a lot for answering so fast!

I did a bit debugging and it looks indeed like that my router is currently not sending the PUBLISHED message. The router is only creating an EVENT message, but PUBLISHED is missing.

2022-02-03T14:39:51-0500 [Router      10810 crossbar.router.protocol.WampWebSocketServerProtocol] WAMP RECV: message=Publish(request=1, topic=3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29.push, args=['WHello'], kwargs=None, acknowledge=None, exclude_me=None, exclude=None, exclude_authid=None, exclude_authrole=None, eligible=None, eligible_authid=None, eligible_authrole=None, retain=None, enc_algo=None, enc_key=None, enc_serializer=None, payload=-, forward_for=None), session=7557342860847853, authid=3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29

2022-02-03T14:39:51-0500 [Router      10810 crossbar.router.router.Router] Validate 'event' for '3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29.push'

2022-02-03T14:39:51-0500 [Router      10810 crossbar.router.role.RouterRole] CrossbarRouterRoleStaticAuth.authorize identity 3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29.push publish

2022-02-03T14:39:51-0500 [Router      10810 crossbar.router.router.Router] Authorized action 'publish' for URI '3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29.push' by session 7557342860847853 with authid '3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29' and authrole 'identity' -> authorization: {'allow': True, 'disclose': False, 'cache': True}

2022-02-03T14:39:51-0500 [Router      10810 crossbar.router.broker.Broker] <crossbar.router.broker.Broker.processPublish>::on_authorize_success() - permission GRANTED for PUBLISH to topic "3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29.push" [realm="test", session_id=7557342860847853, authid="3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29", authrole="identity"]

2022-02-03T14:39:51-0500 [Router      10810 crossbar.router.broker.Broker] dispatching for subscription=ExactUriObservation(id=2741518893347922, uri=3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29.push, match=exact, ordered=False, extra=<crossbar.router.broker.SubscriptionExtra object at 0x1187afbb0>, created=2022-02-03T19:39:51.302Z, observers={<crossbar.router.session.RouterSession object at 0x1187238e0>}), storing_event=False

2022-02-03T14:39:51-0500 [Router      10810 crossbar.router.broker.Broker] unchunked dispatching to 1 receivers

2022-02-03T14:39:51-0500 [Router      10810 crossbar.router.protocol.WampWebSocketServerProtocol] WAMP SEND: message=Event(subscription=2741518893347922, publication=8264063572469899, args=['Hello'], kwargs=None, publisher=None, publisher_authid=None, publisher_authrole=None, topic=None, retained=None, enc_algo=None, enc_key=None, enc_serializer=None, payload=-, forward_for=None), session=3677469751106487, authid=3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29

I use crossbar.io v21.3.1 as a router. Right now I don't do anything fancy yet. I just added a dynamic authenticator.

If I read the spec correctly, a broker need to send PUBLISHED to the publisher to acknowledge publication, but this message seem to be not generated. And the EVENT message seem to be the mechanism to inform the subscribers. So I guess your implementation is correct.

Not sure what to do now. I guess I need to check the router implementation. If you have any idea what could be the reason for this behaviour, let me know :)

@aarlt
Copy link
Author

aarlt commented Feb 4, 2022

This issue seem to be related to a missing PUBLISHED message. My router implementation is not generating that needed message. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants