falcon: Falcon not working properly locally on MacOS (m1) in forked mode

Hello!

When I run be falcon host & make a simple health check request I got this in .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/pg-1.5.4/lib/pg/connection.rb:690:

Снимок экрана 2024-03-01 в 19 30 05

And then have a server restart.

When I use be falcon serve -b http:/localhost:3000, get this endless forked loop:

Снимок экрана 2024-03-01 в 19 34 31

be falcon serve -b --threaded http:/localhost:3000 works fine. No problems inside Docker even with forked mode.

ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
falcon (0.42.3)

Any thoughts, suggestions? How to correctly run the forked mode in MacOS (m1)?

Much appreciated in advance!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

@jf try setting OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES this worked for me.

Hey, karafka author here: https://karafka.io/docs/Forking/#forking-issues-on-macos

macos dynlibs need to be loaded pre-fork. No option to bypass this securely. Also no karafka components (including raw rdkafka usage) can be done pre-fork.

one suggestion if I may: you want to make it as easy as possible for folks to run your sample code.

It took a while for me to try to run the example:

  1. first up, I had to get the PG.connect parameters right (I think dbname: 'postgres' is probably a better assumption for folks’ setup than dbname: 'test'?)
  2. having not much experience with falcon (really I came to falcon by way of roda-websockets, as mentioned), it took a while for me to figure out that I should be doing falcon host /path/to/example/pgfault/falcon.rb (as opposed to simply ruby /path/to/...)

It does not look like I have any issue with pg (but again, my issue is using rdkafka with falcon):

  0.0s     info: Falcon::Command::Host [oid=0x7d0] [ec=0x7e4] [pid=73820] [2024-05-20 21:12:16 +0800]
               | Falcon Host v0.47.6 taking flight!
               | - Configuration: /Users/jf/PROJS/falcon/examples/pgfault/falcon.rb
               | - To terminate: Ctrl-C or kill 73820
               | - To reload: kill -HUP 73820
#<PG::Connection:0x000000012071d6a0 host=127.0.0.1 port=5432 user=postgres>
 0.18s     info: Falcon::Service::Server [oid=0xb90] [ec=0x7e4] [pid=73820] [2024-05-20 21:12:16 +0800]
               | Starting hello.localhost on #<Falcon::ProxyEndpoint endpoint=#<IO::Endpoint::UNIXEndpoint "/Users/jf/PROJS/falcon/examples/pgfault/application.ipc">>

I’m encountering the same report from falcon, except my issue has to do with rdkafka, rather than with pg.

  0.0s     info: Falcon::Command::Serve [oid=0x85c] [ec=0x870] [pid=94063] [2024-05-16 23:49:44 +0800]
               | Falcon v0.47.6 taking flight! Using Async::Container::Forked {:count=>12, :restart=>true}.
               | - Binding to: #<Falcon::Endpoint https://localhost:9292/ {}>
               | - To terminate: Ctrl-C or kill 94063
               | - To reload configuration: kill -HUP 94063
 0.04s     info: Falcon::Service::Server [oid=0x8fc] [ec=0x870] [pid=94063] [2024-05-16 23:49:44 +0800]
               | Starting server on #<Falcon::Endpoint https://localhost:9292/ {}>
objc[94074]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[94074]: +[__NSCFConstantString 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.
 3.65s    error: Async::Container::Forked [oid=0xaf0] [ec=0xb04] [pid=94063] [2024-05-16 23:49:47 +0800]
               | pid 94074 SIGABRT (signal 6)

I am basically using https://github.com/socketry/roda-websockets/blob/main/examples/interactive_browser/config.ru, but adding this block within r.websocket to create a consumer for kafka:

          consumer = Rdkafka::Config.new(KAFKA_CONFIG).consumer
          consumer.subscribe('test-topic')

          consumer.each do |mesg|
            p msg
          end

And that’s all it takes to get this error for Falcon. I wish I could resolve this easily myself… but I’m stuck

Okay, thanks, I’ll try to reproduce this.