question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

the unix listener closes the connection unexpectedly with: echo foo | nc -U /tmp/mysock

See original GitHub issue

I tried the following example on the AnyIO documentation:

from anyio import create_unix_listener, run


async def handle(client):
    async with client:
        name = await client.receive(4) # I changed the value
        await client.send(b'Hello, %s\n' % name)


async def main():
    listener = await create_unix_listener('/tmp/mysock')
    await listener.serve(handle)

run(main)

When sending a string with echo foo | nc -U /tmp/mysock the answer is never printed. However running nc -U /tmp/mysock interactively it is working.

Also this callback works as expected with asyncio.start_unix_server():

    async def _handle_request(self, reader, writer):
        line = await reader.readline()
        writer.write(line)
        await writer.drain()
        writer.write_eof()
        writer.close()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
agronholmcommented, Feb 21, 2021

Ok, I figured it out. There’s something I didn’t know – you have to return True from a Protocol’s eof_received() method, or else the transport will be shut down.

0reactions
agronholmcommented, Feb 27, 2021

Fixed via 3b4c6495, released in v2.2.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

netcat: send text to echo service, read reply then exit
The problem is that nc will close the connection immediately after stdin is closed, which is very quick for a simple my_command string,...
Read more >
psql: server closed the connection unexepectedly
If the connection aborts randomly I'd suspect network issues. Again, what does the log on the PostgreSQL server say about these terminated ...
Read more >
How to automatically close netcat connection after data is sent?
I am executing the following command from a script: echo '{"hostUp": true}' | sudo ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found