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

[NSString initialize] may have been in progress in another thread when fork() was called #246

Closed
skaji opened this issue Apr 28, 2024 · 2 comments · Fixed by #247
Closed

Comments

@skaji
Copy link
Owner

skaji commented Apr 28, 2024

cpm calls fork(2) internally.

If you use cpm on macOS, you may get errors like

❯ cpm install Foo::Bar
objc[80048]: +[NSString initialize] may have been in progress in another thread when fork() was called.
objc[80048]: +[NSString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
...
# FAIL

An easy workaround is to set environment variable OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES:

❯ env OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES cpm install Foo::Bar
# OK

Should this issue be fixed in perl itself?

See https://bugs.ruby-lang.org/issues/14009

@skaji
Copy link
Owner Author

skaji commented Apr 28, 2024

minimal test case:

#!/usr/bin/env perl
use strict;
use warnings;

use Cwd;
use Socket 'inet_aton';

my $pid = fork // die;

if ($pid == 0) {
    inet_aton "invalid";
    exit;
}

wait;
❯ /usr/bin/perl test.pl
objc[34292]: +[NSString initialize] may have been in progress in another thread when fork() was called.
objc[34292]: +[NSString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

@skaji
Copy link
Owner Author

skaji commented Apr 29, 2024

Real world example:

# app.pl
use Mojolicious::Lite -signatures;

get '/' => sub ($c) {
  my $code = $c->app->ua->get("http://www.google.com")->result->code;
  $c->render(text => "google returns $code\n");
};

app->start;
❯ curl -fsSL https://cpanmin.us | /usr/bin/perl - -nq -Llocal Mojolicious
Successfully installed Mojolicious-9.36
1 distribution installed

❯ env PERL5LIB=$PWD/local/lib/perl5 /usr/bin/perl local/bin/hypnotoad -f app.pl
...

# access http://localhost:8080, then...

objc[35100]: +[NSString initialize] may have been in progress in another thread when fork() was called.
objc[35100]: +[NSString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
[2024-04-29 10:03:29.88360] [35097] [info] Worker 35100 stopped
[2024-04-29 10:03:29.88693] [35104] [info] Worker 35104 started

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

Successfully merging a pull request may close this issue.

1 participant