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

ZMQ error when starting second omc session #64

Closed
AnHeuermann opened this issue Jul 13, 2022 · 5 comments
Closed

ZMQ error when starting second omc session #64

AnHeuermann opened this issue Jul 13, 2022 · 5 comments
Assignees

Comments

@AnHeuermann
Copy link
Member

AnHeuermann commented Jul 13, 2022

Description

When I create an OMCSession, close it with quit and open a new one ZMQ throws an error.

Strangely this works perfectly fine on all of my machines but one.
This also works fine in the virtual machines of the GitHub actions CI of a package I'm developing.

How to reproduce

julia> using OMJulia
julia> omc= OMJulia.OMCSession()
[ Info: Path to zmq file="/tmp/openmodelica.USERNAME.port.julia.LxagFYK6UA"
OMJulia.OMCSession(false, false, Dict{Any, Any}(), Dict{Any, Any}(), Dict{Any, Any}(), "", "/path/to/my/workingDir.jl, "", "", "", #undef, "", "", Any[], Dict{Any, Any}(), Dict{Any, Any}(), Dict{Any, Any}(), Dict{Any, Any}(), Dict("startTime" => "0.0", "stopTime" => "1.0", "numberOfIntervals" => "500", "stepSize" => "0.002", "tolerance" => "1e-6"), "", false, "", #undef, #undef, #undef, #undef, ZMQ.Context(Ptr{Nothing} @0x0000000001e83710, WeakRef[WeakRef(ZMQ.Socket(Ptr{Nothing} @0x0000000002423650, FileWatching._FDWatcher(Ptr{Nothing} @0x0000000001726890, 39, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.InvasiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false))))]), ZMQ.Socket(Ptr{Nothing} @0x0000000002423650, FileWatching._FDWatcher(Ptr{Nothing} @0x0000000001726890, 39, (1, 0), Base.GenericCondition{Base.Threads.SpinLock}(Base.InvasiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), 0, (false, false))), Process(`omc --interactive=zmq +z=julia.LxagFYK6UA`, ProcessRunning))
julia> OMJulia.sendExpression(omc, "quit()",parsed=false)
"quit requested, shutting server down\n"
julia> omc= OMJulia.OMCSession()
[ Info: Path to zmq file="/tmp/openmodelica.USERNAME.port.julia.xnIupNqu5H"
ERROR: ZMQ.StateError("Invalid argument")
Stacktrace:
 [1] connect
   @ ~/.julia/packages/ZMQ/R3wSD/src/socket.jl:65 [inlined]
 [2] OMJulia.OMCSession(omc::Nothing)
   @ OMJulia ~/.julia/packages/OMJulia/pPJUC/src/OMJulia.jl:176
 [3] OMJulia.OMCSession()
   @ OMJulia ~/.julia/packages/OMJulia/pPJUC/src/OMJulia.jl:88
 [4] top-level scope
   @ REPL[6]:1

Versions 'n stuff

OMJulia.jl: v0.2.0 https://github.com/OpenModelica/OMJulia.jl#master (should be d705d58)
ZMQ.jl: v1.2.1
OS: Ubuntu 20.04.4 LTS
OpenModelica: v1.20.0-dev-211-g882357bebd
Julia Version 1.7.2 (Commit bf53498635 (2022-02-06 15:21 UTC))
CPU: Intel(R) Xeon(R) Gold 6248R CPU @ 3.00GHz
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, cascadelake)

@AnHeuermann
Copy link
Member Author

Okay, this has nothing to do with the second run.

The only way I can get it to work for me is to un-coment the sleep(5) in https://github.com/OpenModelica/OMJulia.jl/blob/master/src/OMJulia.jl/#L161.

There has to be a way to check if the process spawned in the pipeline is already up and running and that we wait for that to happen.

this.omcprocess = open(pipeline(`omc $args2 $args3$args4`))

I tried @async and wait but without success.

@JKRT
Copy link
Member

JKRT commented Jul 13, 2022

@AnHeuermann What happens if you run Julia with Julia -O0 ?

Just curious because I remember I did some kind of hack to avoid having the Julia compiler remove code in one of the loops.

We could add the sleep again, the issue is that it is not guaranteed to work either (Flaky, in the sense it might still fail once every full moon or so).

Maybe it would be good anyway to add:
Base.Experimental.@compiler_options(optimize=0, compile=min, infer=no)
Since this package does not do anything computationally heavy, we should see some speedups, especially when starting the package.

@AnHeuermann
Copy link
Member Author

AnHeuermann commented Jul 13, 2022

I added

        tries = 0
        while tries < 100 && !isfile(joinpath("/tmp", portfile))
            @info "Sleep"
            sleep(0.02)
            tries += 1
        end

and this works. Not great but better than nothing. I would remove the @info and add a timeout error though.

@AnHeuermann
Copy link
Member Author

Using Julia -O0 changes nothing (as far as I can see).

@arun3688
Copy link
Contributor

@AnHeuermann the main issue, the process is spawned, but the ZMQFile generated is not available by the time, when we want to read, sleep should do the trick, but this code should also do the trick

      while true
           # Necessary or Julia might optimize away checking isfile every iteration
           global IS_FILE_OMJULIA = isfile(fullpath)
           if (IS_FILE_OMJULIA)
               filedata = read(fullpath, String)
               break
           end
       end 

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

3 participants