Using zeromq sockets with mojolicious on hypnotoad server

124 views
Skip to first unread message

Nikita Dubrovin

unread,
Jun 19, 2013, 8:11:51 AM6/19/13
to mojol...@googlegroups.com
Hello.

I am trying to implement an application event feed with zmq PUB/SUB sockets and XPUB/XSUB broker, to distribute global state updates to web-clients. If an event has fired, (e. g. record in database was deleted), it is published to PUB socket, then server worker processes receive it and forward to clients through websocket.

Looks like I have a problem initializing publish socket: messages sent by separate script are received by clients. If I try to create it at application startup, hypnotoad runs a single query 'GET /' (when i refresh page) and crashes:

-> % hypnotoad -f script/web_socket_simple
Server available at http://127.0.0.1:8080.
Assertion failed: ok (mailbox.cpp:79)
[2]    8095 abort (core dumped)  hypnotoad -f script/web_socket_simple

If i comment line with init_publish_socket method invocation and dependent code(lines 27-31 in Application Gist), application works normally, but without publish socket.

Here's my application:


Also, i have questions:

1. When I need to init PUB socket in application?
2. Should PUB and SUB socket share the same context?
3. Is it necessary to use XSUB/XPUB broker when i have multiple application workers, or simple PUB/SUB will suffice?

Charlie Brady

unread,
Jun 19, 2013, 11:20:07 AM6/19/13
to mojol...@googlegroups.com


On Wed, 19 Jun 2013, Nikita Dubrovin wrote:

> Hello.
>
> I am trying to implement an application event feed with zmq PUB/SUB sockets
> and XPUB/XSUB broker, to distribute global state updates to web-clients. If
> an event has fired, (e. g. record in database was deleted), it is published
> to PUB socket, then server worker processes receive it and forward to
> clients through websocket.
>
> Looks like I have a problem initializing publish socket: messages sent by
> separate script are received by clients. If I try to create it at
> application startup, hypnotoad runs a single query 'GET /' (when i refresh
> page) and crashes:
>
> -> % hypnotoad -f script/web_socket_simple
> Server available at http://127.0.0.1:8080.
> Assertion failed: ok (mailbox.cpp:79)
> [2] 8095 abort (core dumped) hypnotoad -f script/web_socket_simple

Looks to be a concurrency problem with zeromq. Doesn't look like a problem
with Mojolicious per se.

https://zeromq.jira.com/browse/LIBZMQ-292
http://comments.gmane.org/gmane.network.zeromq.devel/12556

I'd guess you need locking somewhere.

Nikita Dubrovin

unread,
Jun 19, 2013, 11:36:00 AM6/19/13
to mojol...@googlegroups.com, charli...@budge.apana.org.au
I've noticed that this crash only happens when publish socket and subscribe socket are created within the same context. When i create them in separate context, crash do not reproduce.

среда, 19 июня 2013 г., 19:20:07 UTC+4 пользователь Charlie Brady написал:
Reply all
Reply to author
Forward
0 new messages