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

IoT.js unexpectedly exits (caused by SIGPIPE) when the active socket is closed by the client #1977

Open
erkopui opened this issue Aug 16, 2021 · 1 comment

Comments

@erkopui
Copy link

erkopui commented Aug 16, 2021

build:

./tools/build.py --jerry-heaplimit=2048 --jerry-profile=es2015-subset

Test code:
test.js

var fs = require("fs")
var http = require("http")
var port = 8888

http.createServer(function(request, response) {
        console.log("Request for path: " + request.url)

        fs.createReadStream("/tmp/100M.bin").pipe(response)
})
.listen(port, function() {
        console.log('HTTP server listening on port: ' + port)
})

#prepeare the file

dd if=/dev/urandom of=/tmp/100M.bin bs=1M count=100

#on the server-side

gdb iotjs/build/x86_64-linux/debug/bin/iotjs
run test.js

#on the client-side

wget -O - localhost:8888 | pv -L 10k > /dev/null
#after a few second, press ctrl + c (close connection)

#GDB result:

Thread 1 "iotjs" received signal SIGPIPE, Broken pipe.
__libc_write (nbytes=4096, buf=0x8157e8, fd=7) at ../sysdeps/unix/sysv/linux/write.c:26
26      ../sysdeps/unix/sysv/linux/write.c: No such file or directory.
(gdb) where
#0  __libc_write (nbytes=4096, buf=0x8157e8, fd=7) at ../sysdeps/unix/sysv/linux/write.c:26
#1  __libc_write (fd=7, buf=0x8157e8, nbytes=4096) at ../sysdeps/unix/sysv/linux/write.c:24
#2  0x000000000059f6fb in uv__write (stream=0x804d80) at /tmp/iotjs/deps/libtuv/src/unix/stream.c:854
#3  0x00000000005a0861 in uv__stream_io (loop=0x803a00 <default_loop_struct>, w=0x804df0, events=29) at /tmp/iotjs/deps/libtuv/src/unix/stream.c:1334
#4  0x00000000005a5477 in uv__io_poll (loop=0x803a00 <default_loop_struct>, timeout=117805) at /tmp/iotjs/deps/libtuv/src/unix/linux-core.c:389
#5  0x0000000000598c9c in uv_run (loop=0x803a00 <default_loop_struct>, mode=UV_RUN_ONCE) at /tmp/iotjs/deps/libtuv/src/unix/core.c:327
#6  0x00000000004200a6 in iotjs_start (env=0x602700 <current_env>) at /tmp/iotjs/src/iotjs.c:233
#7  0x0000000000420386 in iotjs_entry (argc=2, argv=0x7fffffffe368) at /tmp/iotjs/src/iotjs.c:312
#8  0x000000000041fb12 in main (argc=2, argv=0x7fffffffe368) at /tmp/iotjs/src/platform/linux/iotjs_linux.c:19

Possible solution somewhere in main thread:

  sigset_t set;
  sigemptyset(&set);
  sigaddset(&set, SIGPIPE);
  pthread_sigmask(SIG_BLOCK, &set, NULL);
@toneyche
Copy link

thank you so much! it's work

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