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

fgets error when leaving Julia #971

Closed
ThomasBreuer opened this issue Mar 4, 2024 · 4 comments
Closed

fgets error when leaving Julia #971

ThomasBreuer opened this issue Mar 4, 2024 · 4 comments

Comments

@ThomasBreuer
Copy link
Member

ThomasBreuer commented Mar 4, 2024

Currently the following happens with Julia 1.8.5. (The problem had been observed in oscar-system/Oscar.jl/pull/3478.)

julia> using GAP
 ┌───────┐   GAP 4.12.2 of 2022-12-18
 │  GAP  │   https://www.gap-system.org
 └───────┘   Architecture: x86_64-pc-linux-gnu-julia1.8-64-kv8
 Configuration:  gmp 6.2.1, Julia GC, Julia 1.8.5, readline
 Loading the library and packages ...
reading ~/.gap/gaprc
 Packages:   AClib 1.3.2, Alnuth 3.2.1dev, AtlasRep 2.1.8, AutPGrp 1.11, 
             Browse 1.8.14, CRISP 1.4.6, Cryst 4.1.25, CrystCat 1.1.10, 
             CTblLib 1.3.7, FactInt 1.6.3, FGA 1.4.0, Forms 1.2.9, 
             GAPDoc 1.6.6.dev, genss 1.6.8, IO 4.8.2, IRREDSOL 1.4.4, 
             JuliaInterface 0.10.2, LAGUNA 3.9.5, orb 4.9.0, Polenta 1.3.10, 
             Polycyclic 2.17dev, PrimGrp 3.4.3, RadiRoot 2.9, recog 1.4.2, 
             ResClasses 4.7.3, SmallGrp 1.5.1, Sophus 1.27, SpinSym 1.5.2, 
             StandardFF 1.0, TomLib 1.2.9, TransGrp 3.6.3, utils 0.85
 Try '??help' for help. See also '?copyright', '?cite' and '?authors'

julia> GAP.Packages.load("sglppow")
true

julia> 
fgets() failed with errno 5
Input/output error
  • Without the load command, I do not get this error message.
  • Loading the package repsn instead of sglppow does not cause the error message.
  • I get the error also when I call GAP.prompt() and then LoadPackage("sglppow") at the GAP prompt.
@ThomasBreuer
Copy link
Member Author

The sglppow package is innocent, the error message comes from the needed package Singular of the LiePRing package, which is a suggested package of sglppow.
When Julia gets terminated, its GAP process gets terminated, and then CloseSingular gets called, via an IntallAtExit call in pkg/singular/gap/singular.g.
This CloseSingular causes the error message:

julia> GAP.Packages.load("Singular")
true

julia> GAP.Globals.StartSingular()

julia> GAP.Globals.CloseSingular()
fgets() failed with errno 5
Input/output error

The Singular package uses GAP's InputOutputLocalProcess in StartSingular and CloseSingular.
Inside a Julia session, one gets an error message as follows (cf. the example in the GAP Reference Manual).

julia> GAP.prompt()
gap> d := DirectoryCurrent();;
gap> f := Filename(DirectoriesSystemPrograms(), "rev");;
gap> s := InputOutputLocalProcess(d,f,[]);
< input/output stream to rev >
gap> CloseStream(s);
rev: stdin: Input/output error

@fingolfin
Copy link
Member

Can't reproduce this on macOS, but I can on Linux. But on Linux I also get the same behavior with a "plain" / "regular" GAP.

So this seems to be a GAP issue, and/or possibly one in the GAP package named "Singular"?

Note that what happens here is that InputOutputLocalProcess do not support capturing stderr, and the message we see is on stderr. Being able to capture stderr has been long on the wishlist, see gap-system/gap#4657 -- it's not technically hard, but "someone" has to do it and test it (and these days "someone" would usually mean me, sadly sigh).

In this particular case, it might also help to first kill the child process / instruct it to shutdown, before brutally closing its input stream. Actually, I wonder if this isn't a bug in the GAP kernel (but I should read up on the exact POSIX semantics of the various involved pieces first):

static Obj FuncCLOSE_PTY_IOSTREAM(Obj self, Obj stream)
{
    UInt pty = HashLockStreamIfAvailable(stream);

    // Close down the child
    int status;
    int retcode = close(PtyIOStreams[pty].ptyFD);
    if (retcode)
        Pr("Strange close return code %d\n", retcode, 0);
    kill(PtyIOStreams[pty].childPID, SIGTERM);

Note how we first close the file descriptor, then call kill -- I would have thought we should do it the other way around? But maybe not, as I said, should first read up on this.

@ThomasBreuer
Copy link
Member Author

@fingolfin Yes, the problem occurs also in plain GAP; I did not notice this because the error message in plain GAP is different: the "Input/output error" is missing.

Can we close this issue, since the problem is now fixed on the GAP side?

@ThomasBreuer
Copy link
Member Author

The problem will be solved in GAP 4.13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants