Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
libflux: changes to message dispatch to support routers #2367
Here are a few changes peeled off from #2354:
Instead of creating a wrapper for each function, create a macro that can wrap any function, e.g. Before: free(item) -> ERRNO_SAFE_FREE(item) After: free(item) -> ERRNO_SAFE_WRAP(free, item) Update users of ERRNO_SAFE_FREE().
Problem: The message dispatcher does not check whether a response message has routes remaining in its route stack before attempting to match an RPC in the matchtag hash. For a module like connector-local acting as a router, this could result in a response being delivered to a connector-local RPC when it should be routed to a downstream client. Refuse to match responses to RPC requests (valid matchtag) unless their route stack is empty. Other message handlers for requests continue to match so that routers can be implemented.
grondo left a comment
LGTM! One comment inline.
Also, I wouldn't normally worry about documentation at this point, but since we already have a
Thanks! Fixed the overlooked glob character, and also another case (empty string topic_glob) that I had missed. Renamed
I also realized that
Finally, updated the man page a suggested.
Problem: Last-in request handlers have the highest priority, which allows built-in module methods to be overridden, but prevents a "fall through" request handler from being registered that would match methods not explicitly registered earlier. Instead of pushing all request handlers onto a list, store non-glob request handlers in a hash by topic string. Requests are first matched in the hash, and fall through to the list if no match. Registering a handler for a duplicate request method replaces the old one. This mimics the current behavior of shadowing an earlier-registered request handler.
Problem: several errors result in flux_msg_recvfd() failing with errno set to EPROTO, including EOF from read(2). Since EOF on read(2) is what we should get when the connection is closed, change the errno to ECONNRESET so it can be suppressed separately from other errors. Update flux-proxy to log EPROTO if returned from recvfd().
Ensure that the dispatcher calls the most recently registered handler for a non-glob request.
Check the following: - a RPC response handler is not overridden by a response handler that matches all responses - a request handler for a specific method is not overridden by a request handler that matches all requests
Check that a response message with a non-empty route stack falls through to a catchall response handler even though there is an RPC response handler waiting for that matchtag.
Problem: flux_msg_match() tries to literally match a glob containing square brackets. The heavy-weight fnmatch() call is avoided in flux_msg_cmp() unless the match.topic_glob contains a glob character, but only '*' and '?' were checked. Add '[' to the check.
Problem: flux_msg_cmp() logic could be clearer The inline tests on topic_glob for "match any" are not documented and a bit obscure. For clarity, pull this test out to a helper named isa_matchany().
@@ Coverage Diff @@ ## master #2367 +/- ## ========================================== + Coverage 80.81% 80.83% +0.01% ========================================== Files 218 218 Lines 34514 34539 +25 ========================================== + Hits 27894 27921 +27 + Misses 6620 6618 -2