Fixed I/O operation on closed file and Bad file descriptor exceptions after running callable aliases multiple times (#5437)

### Motivation

Closes #5435.

### After

After this fix I can't reproduce this:
* https://github.com/xonsh/xonsh/issues/5241#issuecomment-1961249511
  * We can revert https://github.com/xonsh/xonsh/pull/5288
* https://github.com/xonsh/xonsh/issues/5393 
  * We can revert https://github.com/xonsh/xonsh/pull/5403

### Next step

Here is the PR for unpin ptk - #5438

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andy Kipp 2024-05-23 20:07:30 +02:00 committed by GitHub
parent 0f25a5a348
commit 1847f8a379
Failed to generate hash of commit
3 changed files with 66 additions and 0 deletions

23
news/fix_io.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Fixed ``Bad file descriptor`` and I/O errors after running callable alias (#5435).
**Security:**
* <news item>

View file

@ -1262,3 +1262,45 @@ def test_suspended_captured_process_pipeline():
assert re.match(
match, out, re.MULTILINE | re.DOTALL
), f"\nFailed:\n```\n{stdin_cmd.strip()}\n```,\nresult: {out!r}\nexpected: {match!r}."
@skip_if_on_windows
@pytest.mark.flaky(reruns=3, reruns_delay=1)
def test_alias_stability():
"""Testing alias stability after amalgamation regress that described in #5435."""
stdin_cmd = (
"aliases['tst'] = lambda: [print('sleep'), __import__('time').sleep(1)]\n"
"tst\ntst\ntst\n"
)
out, err, ret = run_xonsh(
cmd=None,
stdin_cmd=stdin_cmd,
interactive=True,
single_command=False,
timeout=10,
)
assert re.match(".*sleep.*sleep.*sleep.*", out, re.MULTILINE | re.DOTALL)
@skip_if_on_windows
@pytest.mark.flaky(reruns=3, reruns_delay=1)
def test_alias_stability_exception():
"""Testing alias stability (exception) after amalgamation regress that described in #5435."""
stdin_cmd = (
"aliases['tst1'] = lambda: [print('sleep'), __import__('time').sleep(1)]\n"
"aliases['tst2'] = lambda: [1/0]\n"
"tst1\ntst2\ntst1\ntst2\n"
)
out, err, ret = run_xonsh(
cmd=None,
stdin_cmd=stdin_cmd,
interactive=True,
single_command=False,
timeout=10,
)
assert re.match(
".*sleep.*ZeroDivisionError.*sleep.*ZeroDivisionError.*",
out,
re.MULTILINE | re.DOTALL,
)
assert "Bad file descriptor" not in out

View file

@ -0,0 +1 @@
from xonsh.procs import proxies # noqa