"Unable to open fd 8 for writing, quitting" on Linux
See original GitHub issueRelevant older issue: https://github.com/kislyuk/argcomplete/issues/142 where I believe users also reported it happening on Linux but it was closed without any resolution (e.g. via suggested use of temporary files).
In my case I have a stock Debian (testing/unstable mix), python 3.8.3rc1 and I observe the same error with our DataLad which recently was fixed up to work (again) with argcomplete and it works for everyone else on the team but (un)lucky me. In the session you below can see that I am getting the exception, and the process has no 8 fd among its fds:
$> _ARC_DEBUG=1 _ARGCOMPLETE=1 datalad --pdb -l 1 --help
[DEBUG ] Command line args 1st pass. Parsed: Namespace() Unparsed: ['--pdb', '--help']
[DEBUG ] Discovering plugins
[DEBUG ] Loading entrypoints
[DEBUG ] Generating detailed description for the parser
[Level 5] Finished setup_parser
> /home/yoh/proj/misc/argcomplete/argcomplete/__init__.py(188)__call__()
-> try:
(Pdb) l
183 except:
184 debug_stream = sys.stderr
185
186 if output_stream is None:
187 import pdb; pdb.set_trace()
188 -> try:
189 output_stream = os.fdopen(8, "wb")
190 except:
191 debug("Unable to open fd 8 for writing, quitting")
192 exit_method(1)
193
(Pdb) os.getpid()
1092474
(Pdb)
[3] + 1092474 suspended _ARC_DEBUG=1 _ARGCOMPLETE=1 datalad --pdb -l 1 --help
$> ls -l /proc/1092474/fd
total 0
lrwx------ 1 yoh yoh 64 May 19 13:48 0 -> /dev/pts/16
lrwx------ 1 yoh yoh 64 May 19 13:48 1 -> /dev/pts/16
lrwx------ 1 yoh yoh 64 May 19 13:48 2 -> /dev/pts/16
lr-x------ 1 yoh yoh 64 May 19 13:48 3 -> pipe:[41232747]
lr-x------ 1 yoh yoh 64 May 19 13:48 5 -> pipe:[41232748]
$> fg
[3] 1092474 continued _ARC_DEBUG=1 _ARGCOMPLETE=1 datalad --pdb -l 1 --help
l
l
194 # print("", stream=debug_stream)
195 # for v in "COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY _ARGCOMPLETE_COMP_WORDBREAKS COMP_WORDS".split():
196 # print(v, os.environ[v], stream=debug_stream)
197
198 ifs = os.environ.get("_ARGCOMPLETE_IFS", "\013")
199 if len(ifs) != 1:
200 debug("Invalid value for IFS, quitting [{v}]".format(v=ifs))
201 exit_method(1)
202
203 comp_line = os.environ["COMP_LINE"]
204 comp_point = int(os.environ["COMP_POINT"])
(Pdb) n
> /home/yoh/proj/misc/argcomplete/argcomplete/__init__.py(189)__call__()
-> output_stream = os.fdopen(8, "wb")
(Pdb)
OSError: [Errno 9] Bad file descriptor
> /home/yoh/proj/misc/argcomplete/argcomplete/__init__.py(189)__call__()
-> output_stream = os.fdopen(8, "wb")
(Pdb)
> /home/yoh/proj/misc/argcomplete/argcomplete/__init__.py(190)__call__()
-> except:
(Pdb) fg
*** NameError: name 'fg' is not defined
(Pdb)
Traceback (most recent call last):
File "/home/yoh/proj/misc/argcomplete/argcomplete/__init__.py", line 189, in __call__
output_stream = os.fdopen(8, "wb")
File "/usr/lib/python3.8/os.py", line 1023, in fdopen
return io.open(fd, *args, **kwargs)
OSError: [Errno 9] Bad file descriptor
in the shell I do get calls which do not explicitly create fd 8 failing:
$> python -c 'import os; os.fdopen(8)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/os.py", line 1023, in fdopen
return io.open(fd, *args, **kwargs)
OSError: [Errno 9] Bad file descriptor
$> python -c 'import os; os.fdopen(8)' 8>&1
$>
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Problems reading\writing to devices for embedded Linux project
I have two file descriptors (fd) to a COM port on an embedded Linux board, one for writing and one for reading. They...
Read more >What permissions are needed to write a PID file in /var/run?
By default, you can only write to /var/run as a user with an effective user ID of 0 (ie as root). This is...
Read more >lsof(8) - Linux manual page - man7.org
+d s causes lsof to search for all open instances of directory s and the files and directories it contains at its top...
Read more >How to Fix the 'Too Many Open Files' Error in Linux?
It means that a process has opened too many files (file descriptors) and cannot open new ones. On Linux, the “max open file...
Read more >Linux Creating a Partition Size Larger Than 2TB - nixCraft
Frankly speaking, you cannot create a Linux partition larger than 2 TB using the fdisk command. The fdisk won't create partitions larger ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
THANK YOU @evanunderscore for the guidance – I am ready to declare “success” in troubleshooting !
since it is argcomplete which generates it, may be it should embed argcomplete version which generated it somewhere in the comment
TL;DR summary: it is interaction between
IFS=$'\013'
which is later ‘exported’ into the underlying process:git-annex
standalone (filed fresh bug report) to @joeyh build shim showing intolerance to thatIFS
causing it to segfault.That also explains why other @datalad/developers didn’t experience this – since they typically do not use standalone git-annex build.
I guess there is nothing wrong done on argcomplete side, so feel free to close this issue, unless you see that you could avoid setting IFS and set some other “argcomplete specific” variable so it might not cause disturbance in some weak tools underneath?
Some additional notes which are no longer pertinent probably
re-doing everything now after
pip install --upgrade argcomplete
to 1.12.0:and verified that it still doesn’t work by trying to complete
datalad inst<TAB>
Thanks for the detailed notes @yarikoptic. Glad you managed to find the source of your problem!
Embedding the argcomplete version in the generated wrapper is a good idea, though currently argcomplete doesn’t have a
__version__
and keeping one in sync with the package version number is a workflow problem that would need to be left to @kislyuk.