Skip to content

Snekbox hangs while reading stdout from NsJail #131

@MarkKoz

Description

@MarkKoz

Description

Snekbox hangs while reading stdout from the NsJail processes. This is handled by NsJail._consume_stdout(). The specific line it hangs on is

chars = nsjail.stdout.read(READ_CHUNK_SIZE)

I believe this happens because the amount of bytes being read is larger than the amount that's in stdout. Hence, the read() call waits until enough bytes become available to satisfy the requested amount.

Reproduction

Run the following commands

pipenv run devsh
python -m snekbox 'print("hello")' --time_limit 0

Wait and observe that Snekbox is not terminating. Press ctrl + c to see the following traceback appear

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/mark/repos/python/snekbox/snekbox/__main__.py", line 35, in <module>
    main()
  File "/home/mark/repos/python/snekbox/snekbox/__main__.py", line 30, in main
    result = NsJail().python3(args.code, nsjail_args=args.nsjail_args, py_args=args.py_args)
  File "/home/mark/repos/python/snekbox/snekbox/nsjail.py", line 183, in python3
    output = self._consume_stdout(nsjail)
  File "/home/mark/repos/python/snekbox/snekbox/nsjail.py", line 120, in _consume_stdout
    chars = nsjail.stdout.read(READ_CHUNK_SIZE)
KeyboardInterrupt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions