Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal an error when internal file descriptor limit is reached (at most 256 files can be open at the same time) #5146

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/streams.gd
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,10 @@ DeclareOperation( "InputTextString", [ IsString ] );
## handles windows-style line endings. This means it should <E>not</E> be used for
## binary data. The <Ref BookName="IO" Oper="IO_File" /> function from the <Package>IO</Package>
## package should be used to access binary data.
## <P/>
## Note: At most 256 files may be open for reading or writing at the same time.
## Use <Ref Oper="CloseStream"/> to close the input stream once you have finished
## reading from it.
## </Description>
## </ManSection>
## <#/GAPDoc>
Expand Down Expand Up @@ -751,6 +755,10 @@ DeclareOperation( "OutputTextString", [ IsList, IsBool ] );
## <C>OutputGzipFile</C> acts identically to <C>OutputTextFile</C>, except it compresses
## the output with gzip.
## <P/>
## Note: At most 256 files may be open for reading or writing at the same time.
## Use <Ref Oper="CloseStream"/> to close the output stream once you have finished
## writing to it.
## <P/>
## <Example><![CDATA[
## gap> # use a temporary directory
## gap> name := Filename( DirectoryTemporary(), "test" );;
Expand Down
1 change: 1 addition & 0 deletions src/sysfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ Int SyFopen(const Char * name, const Char * mode, BOOL transparent_compress)

if ( fid == ARRAY_SIZE(syBuf) ) {
HashUnlock(&syBuf);
ErrorReturnVoid("Too many open files (internal file descriptor limit reached)", 0, 0, "you can 'return;'");
return (Int)-1;
}

Expand Down
10 changes: 9 additions & 1 deletion tst/testinstall/streams.tst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#@local dir,fname,file,line,stream,tmpdir,res
#@local dir,fname,file,line,stream,tmpdir,res,streams,i
gap> START_TEST("streams.tst");

#
Expand Down Expand Up @@ -209,5 +209,13 @@ Error, <byte> must an integer between 0 and 255
gap> SetPrintFormattingStatus(stream, fail);
Error, Print formatting status must be true or false

# too many open files
gap> streams := [ ];;
gap> for i in [ 1 .. 300 ] do
> Add( streams, OutputTextFile( fname, false ) );
> od;;
Error, Too many open files (internal file descriptor limit reached)
gap> Perform( streams, CloseStream );

#
gap> STOP_TEST( "streams.tst", 1);