Skip to content

Commit

Permalink
Fix error when Stream is closed after container stopped (#608)
Browse files Browse the repository at this point in the history
* Fix error when Stream is closed after container stopped

* Add changelog
  • Loading branch information
romasku committed Jul 23, 2021
1 parent e35e969 commit 72c1573
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/608.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix an error when attach/exec when container stops before close connection to it.
2 changes: 1 addition & 1 deletion aiodocker/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def close(self) -> None:
return
self._closed = True
transport = self._resp.connection.transport
if transport.can_write_eof():
if transport and transport.can_write_eof():
transport.write_eof()
self._resp.close()

Expand Down
24 changes: 24 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,30 @@ async def test_attach_nontty(docker, image_name, make_container, stderr):
assert data.strip() == b"Hello"


@pytest.mark.asyncio
async def test_attach_nontty_wait_for_exit(docker, image_name, make_container):
cmd = ["python", "-c", "import time; time.sleep(3); print('Hello')"]

config = {
"Cmd": cmd,
"Image": image_name,
"AttachStdin": False,
"AttachStdout": False,
"AttachStderr": False,
"Tty": False,
"OpenStdin": False,
"StdinOnce": False,
}

container = await make_container(
config,
name="aiodocker-testing-attach-nontty-wait-for-exit",
)

async with container.attach(stdin=False, stdout=True, stderr=True):
await asyncio.sleep(10)


@pytest.mark.asyncio
async def test_attach_tty(docker, image_name, make_container):
skip_windows()
Expand Down

0 comments on commit 72c1573

Please sign in to comment.