Giter Site home page Giter Site logo

Comments (10)

sogaiu avatar sogaiu commented on May 23, 2024 2

I got the segfault as well.

I edited src/conf/janetconf.h to have:

#define JANET_EV_NO_EPOLL

and rebuilt janet to reproduce with the code in the comment above.

I don't know how reliable the results are but I used rr to record execution and then snooped around a bit using rr replay.

This is the output I got around the report of a segfault:

Thread 2 received signal SIGSEGV, Segmentation fault.
0x00007f05b167366e in janet_stream_close_impl (stream=<optimized out>) at src/core/ev.c:349
349	        JanetStream *last = janet_vm.streams[j];

I guess that's this line.

from janet.

czkz avatar czkz commented on May 23, 2024 1

I used "TCP Echo Server" example from README as the server and janet -e '(def c (net/connect "127.0.0.1" 8000)) (:write c "abc") (ev/sleep 1e10)' as client.
The server gets stuck in a busy loop after the client sends some data.
Janet compiled with meson setup build && ninja -C build.

0ff8f58 is the first bad commit.
The commit is quite big unfortunately.

Server strace before commit (fd=5 - connection socket):

<...>
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}, {fd=5, events=POLLIN}], 3, -1
<waits for data>

Server strace after commit (fd=5 - connection socket):

<...>
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}, {fd=5, events=POLLIN|POLLOUT}], 3, -1) = 1 ([{fd=5, revents=POLLOUT}])
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}, {fd=5, events=POLLIN|POLLOUT}], 3, -1) = 1 ([{fd=5, revents=POLLOUT}])
poll([{fd=3, events=POLLIN}, {fd=6, events=POLLIN}, {fd=5, events=POLLIN|POLLOUT}], 3, -1) = 1 ([{fd=5, revents=POLLOUT}])
<...>

From man poll:
POLLIN - There is data to read.
POLLOUT - Writing is now possible.

Janet doesn't want to write anything to the socket, yet still waits for it to be writable. Poll immediately signals that it is writable, hence the busy loop.

from janet.

bakpakin avatar bakpakin commented on May 23, 2024 1

Found the issue, the problem is that passing a valid file descriptor to poll with events = 0 immediately returns with POLLHUP.

See https://groups.google.com/g/comp.unix.programmer/c/bNNadBIEpTo/m/G5gs1mqNhbIJ?pli=1 for a conversation and workaround.

from janet.

bakpakin avatar bakpakin commented on May 23, 2024 1

@czkz Thanks for that secondary repro, that seems to be a closely related issue with the poll backend. This is not fixed by a9b8f8e however

from janet.

amano-kenji avatar amano-kenji commented on May 23, 2024

With epoll=false, the following code causes segmentation fault.

(import spork/sh)
(def devnull (sh/devnull))
(ev/spawn-thread (ev/write devnull "ok"))

Welcome to hell.

from janet.

bakpakin avatar bakpakin commented on May 23, 2024

The issue is the copying of streams between threads. There is some thread local (interpreter global) state that needs copying. This only exists for the poll implementation, though.

from janet.

bakpakin avatar bakpakin commented on May 23, 2024

This should be fixed for me as of 12630d3 - the issue was janet_unmarshal_stream didn't re-register the stream with the event loop.

from janet.

amano-kenji avatar amano-kenji commented on May 23, 2024

I built the latest commit with epoll=false, and this issue can still be reproduced with the sample code above.

from janet.

bakpakin avatar bakpakin commented on May 23, 2024

Is the segfault still happening? The 100% cpu is not yet addressed

from janet.

amano-kenji avatar amano-kenji commented on May 23, 2024

At least, the segmentation fault is gone now. The 100% cpu usage is not gone, yet.

from janet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.