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

fs.access causes abort() when run in Emacs shell #6563

Closed
freesteph opened this issue May 4, 2016 · 15 comments · Fixed by #6796
Closed

fs.access causes abort() when run in Emacs shell #6563

freesteph opened this issue May 4, 2016 · 15 comments · Fixed by #6796
Labels
fs Issues and PRs related to the fs subsystem / file system. libuv Issues and PRs related to the libuv dependency or the uv binding.

Comments

@freesteph
Copy link

  • Version: v6.0.0
  • Platform: OSX: Darwin steph-mbp 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
  • Subsystem: GNU Emacs 25.0.93.1 (might affect other clients?)

After upgrading 6.0, I can't run npm in an Emacs subshell because it crashes on any call to fs.access; I'm aware this might be Emacs-specific (works fine in iTerm + ZSH) but in the slim case this is an actual regression I'm attaching the full stacktrace from my system.

node_2016-05-04-104139_Stephanes-MacBook-Pro.crash.txt

@bnoordhuis
Copy link
Member

According to the stack trace, the problem is that libuv can't spawn threads for its thread pool. Perhaps emacs sets ulimit -u too low. Does env UV_THREADPOOL_SIZE=1 npm <cmd> work?

@freesteph
Copy link
Author

Unfortunately it still crashes. I have tried with Emacs's multi-term, ansi-term, eshell and shell and they all crash on this program:

var fs = require('fs');

fs.access('/usr/local/bin/node', fs.X_OK, function (er) {
  console.log('this never prints out');
});

removing the fs.access call makes the program terminates normally.

@freesteph
Copy link
Author

Also, ulimit -u returns 709 in both my normal ZSH prompt and the Emacs-wrapped ZSH prompt.

@mscdex mscdex added the fs Issues and PRs related to the fs subsystem / file system. label May 4, 2016
@bnoordhuis
Copy link
Member

bnoordhuis commented May 5, 2016

If the stack trace is still the same, then emacs must be doing something that prevents node/libuv from operating normally.

I could make libuv print a nicer error message or trudge on in single-thread mode but that's a workaround more than anything else (and it met with some opposition from other maintainers last time I proposed it.)

@ianmcdonald
Copy link

When running v6.0.0 in emacs 24.5.1 (the most current version from Homebrew on OS X), I face a similar situation.

Running any node command from a terminal or shell bash session within emacs, even just running node or npm init throws Abort trap: 6.

Outside of emacs with v.6.0.0, everything is cool.

Inside emacs with with v.5.9.1, everything is cool.

@bnoordhuis
Copy link
Member

I wonder if it's because of 204f3a8 where we bumped MACOSX_DEPLOYMENT_TARGET from 10.5 to 10.7. What happens when you revert that commit and rebuild?

@rej156
Copy link

rej156 commented May 9, 2016

Reporting the same problem!
Abort trap: 6 in any emacs shell with node v6.0.0 and node v6.1.0.

@evanlucas
Copy link
Contributor

Confirmed on v6+ for me. https://github.com/libuv/libuv/blob/v1.x/src/unix/thread.c#L86 is returning 22.

@kouhin
Copy link

kouhin commented May 10, 2016

Maybe same problem.
Flycheck(with eslint) and company-tern can't work after upgrading 6.0.0 and 6.1.0

@bnoordhuis
Copy link
Member

@evanlucas Errno 22 is EINVAL. Is it possible that rlim_cur isn't a multiple of 4096?

@evanlucas
Copy link
Contributor

On my system, that is the case. rlim_cur is 8720000 for some reason

@bnoordhuis
Copy link
Member

Okay, that explains it. Does this patch fix it?

diff --git a/deps/uv/src/unix/thread.c b/deps/uv/src/unix/thread.c
index c35bc92..56bb8a4 100644
--- a/deps/uv/src/unix/thread.c
+++ b/deps/uv/src/unix/thread.c
@@ -28,6 +28,7 @@

 #include <sys/time.h>
 #include <sys/resource.h>  /* getrlimit() */
+#include <unistd.h>  /* getpagesize() */

 #include <limits.h>

@@ -82,10 +83,13 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
   if (pthread_attr_init(attr))
     abort();

-  if (lim.rlim_cur != RLIM_INFINITY &&
-      lim.rlim_cur >= PTHREAD_STACK_MIN) {
-    if (pthread_attr_setstacksize(attr, lim.rlim_cur))
-      abort();
+  if (lim.rlim_cur != RLIM_INFINITY) {
+    /* pthread_attr_setstacksize() expects page-aligned values. */
+    lim.rlim_cur -= lim.rlim_cur % (rlim_t) getpagesize();
+
+    if (lim.rlim_cur >= PTHREAD_STACK_MIN)
+      if (pthread_attr_setstacksize(attr, lim.rlim_cur))
+        abort();
   }
 #else
   attr = NULL;

@evanlucas
Copy link
Contributor

@bnoordhuis I'm thinking that libuv/libuv@3db07cc is what is exposing this issue. Pulling that out fixes it

@evanlucas
Copy link
Contributor

ah didn't see your comment when I posted @bnoordhuis. Confirmed that applying this patch fixes the issue for me. Yay!!!

@evanlucas evanlucas added the libuv Issues and PRs related to the libuv dependency or the uv binding. label May 10, 2016
bnoordhuis added a commit to bnoordhuis/libuv that referenced this issue May 10, 2016
pthread_attr_setstacksize() expects that the stack size is a multiple of
the page size so make sure that it is.

Fixes a regression introduced in commit 3db07cc ("osx: set the default
thread stack size to RLIMIT_STACK") that made the program abort under
certain configurations; GNU Emacs on OS X apparently sets RLIMIT_STACK
to odd values when executing child processes.

Fixes: nodejs/node#6563
@bnoordhuis
Copy link
Member

Good to hear. Libuv PR: libuv/libuv#864

bnoordhuis added a commit to bnoordhuis/libuv that referenced this issue May 10, 2016
pthread_attr_setstacksize() expects that the stack size is a multiple of
the page size so make sure that it is.

Fixes a regression introduced in commit 3db07cc ("osx: set the default
thread stack size to RLIMIT_STACK") that made the program abort under
certain configurations; GNU Emacs on OS X apparently sets RLIMIT_STACK
to odd values when executing child processes.

Fixes: nodejs/node#6563
PR-URL: libuv#864
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
saghul added a commit to saghul/node that referenced this issue May 17, 2016
Fixes: nodejs#4002
Fixes: nodejs#5384
Fixes: nodejs#6563
Refs: nodejs#2680 (comment)
PR-URL: nodejs#6796
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
evanlucas pushed a commit that referenced this issue May 17, 2016
Fixes: #4002
Fixes: #5384
Fixes: #6563
Refs: #2680 (comment)
PR-URL: #6796
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
saghul added a commit to saghul/node that referenced this issue Jul 11, 2016
Fixes: nodejs#4002
Fixes: nodejs#5384
Fixes: nodejs#6563
Refs: nodejs#2680 (comment)
PR-URL: nodejs#6796
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this issue Jul 11, 2016
Fixes: #4002
Fixes: #5384
Fixes: #6563
Refs: #2680 (comment)
PR-URL: #6796
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this issue Jul 11, 2016
Fixes: #4002
Fixes: #5384
Fixes: #6563
Refs: #2680 (comment)
PR-URL: #6796
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this issue Jul 12, 2016
Fixes: #4002
Fixes: #5384
Fixes: #6563
Refs: #2680 (comment)
PR-URL: #6796
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this issue Jul 14, 2016
Fixes: #4002
Fixes: #5384
Fixes: #6563
Refs: #2680 (comment)
PR-URL: #6796
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
MylesBorins pushed a commit that referenced this issue Jul 14, 2016
Fixes: #4002
Fixes: #5384
Fixes: #6563
Refs: #2680 (comment)
PR-URL: #6796
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
brimworks pushed a commit to brimworks/libuv that referenced this issue Oct 18, 2016
pthread_attr_setstacksize() expects that the stack size is a multiple of
the page size so make sure that it is.

Fixes a regression introduced in commit 3db07cc ("osx: set the default
thread stack size to RLIMIT_STACK") that made the program abort under
certain configurations; GNU Emacs on OS X apparently sets RLIMIT_STACK
to odd values when executing child processes.

Fixes: nodejs/node#6563
PR-URL: libuv#864
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
ararslan pushed a commit to JuliaAttic/libuv-archive that referenced this issue Oct 17, 2017
pthread_attr_setstacksize() expects that the stack size is a multiple of
the page size so make sure that it is.

Fixes a regression introduced in commit 3db07cc ("osx: set the default
thread stack size to RLIMIT_STACK") that made the program abort under
certain configurations; GNU Emacs on OS X apparently sets RLIMIT_STACK
to odd values when executing child processes.

Fixes: nodejs/node#6563
PR-URL: libuv/libuv#864
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
(cherry picked from commit 28d160f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. libuv Issues and PRs related to the libuv dependency or the uv binding.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants