Skip to content

Commit

Permalink
Fix Docker Freezing (#153)
Browse files Browse the repository at this point in the history
* Fix #151 Docker Freezing

* Use timeout to replace blocking sleep

* Remove unnecessary import
  • Loading branch information
rnehra01 authored and afeena committed Jun 17, 2017
1 parent e64aba8 commit 9e20f5b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tanner/emulators/cmd_exec.py
@@ -1,6 +1,7 @@
import asyncio
import docker
import yarl
import concurrent
# TODO : Replace docker with aiodocker
import logging

Expand Down Expand Up @@ -51,10 +52,15 @@ async def create_attacker_env(self, session):
return container

async def get_cmd_exec_results(self, container, cmd):
execute_result = None
execute_result = ''
try:
container.start()
execute_result = container.exec_run(['sh', '-c', cmd]).decode('utf-8')
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
cmd_future = executor.submit(container.exec_run, ['sh', '-c', cmd])
try:
execute_result = cmd_future.result(timeout= 1).decode('utf-8')
except concurrent.futures.TimeoutError as timeout_error:
self.logger.error('Error while executing %s in container %s', cmd, timeout_error)
container.kill()
except docker.errors.APIError as server_error:
self.logger.error('Error while executing command %s in container %s', cmd, server_error)
Expand Down

0 comments on commit 9e20f5b

Please sign in to comment.