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

Add Unix socket broker #125

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add Unix socket broker #125

wants to merge 3 commits into from

Conversation

AlanCoding
Copy link
Member

This is maybe, perhaps, a solution to #100 but it is debatable.

However, it was part of the vision of dispatcherctl described in #61

This was more complicated than I expected, but I got it working.

Using the "old" demo with 2 terminal tabs.

# tab 1
PYTHONPATH=. dispatcherd
# tab 2
./run_demo.py

It now get a bit awkward because you can no longer get a response from multiple servers. But we get to the end of the demo, and it prints everything. In my first pass it broke half-way through because the message was longer than 1024. I think I'm still putting in "reply_to" which the server just ignores.

Protocols need to be updated and basically everything aside from making it run the demo once, which is all it does right now.

@AlanCoding
Copy link
Member Author

Oh, here's an interesting find from the demo output:

  Task-234 is done=False
   trace:
Stack for <Task pending name='Task-234' coro=<Broker._add_client() running at /home/alancoding/repos/dispatcher/dispatcher/brokers/socket.py:45> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[StreamReaderProtocol.connection_made.<locals>.callback() at /usr/lib64/python3.12/asyncio/streams.py:248]> (most recent call last):
  File "/home/alancoding/repos/dispatcher/dispatcher/brokers/socket.py", line 45, in _add_client
    line = await client.reader.readline()

It's right about where we expected it to be.

@AlanCoding
Copy link
Member Author

Again, I hit an issue where it will be difficult to move forward before #121 lands.

When running commands as dispatcherctl entrypoint (the ultimate point of this), it can hang waiting for a reply. (yes this means timeout isn't working)

The reply isn't coming because origin information is 0. This is, predictably, because the control.py module has not had its contract updated to the same as DispatcherMain. However, the PR 121 removes the need to copy this contract in the first place. So that's where this leaves us.

@AlanCoding
Copy link
Member Author

I figured out what it was. In asyncio, there are problems having parallel tasks both listening and writing to the same connection. This is roughly the same issue I hit with pg_notify. The solution is same in form, except for the multiple tasks for different clients.

@AlanCoding AlanCoding marked this pull request as ready for review March 17, 2025 17:28
@AlanCoding AlanCoding changed the title [still-demo] Add Unix socket broker Add Unix socket broker Mar 17, 2025
@AlanCoding AlanCoding added the enhancement New feature or request label Mar 17, 2025
Protocol the brokers

Run demo dispatcherctl over socket

Add socket broker unit tests
Add socket broker usage integration tests

Work out issues with test scope and server not opening client connections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant