Open jhuleatt opened 1 year ago
It seems like this might be specific to MacOS. Following the advice in this StackOverflow answer fixes the issue, but I'm not sure if it is something we want to recommend.
Having the same issue. Above solution did not work for me.
> objc[61886]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
> objc[61886]: +[__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.
` from firebase_functions import firestore_fn, https_fn
from firebase_admin import initialize_app, firestore
import google.cloud.firestore
from langchain.llms import OpenAI
app = initialize_app()
@https_fn.on_request()
def askQuestion(req: https_fn.Request) -> https_fn.Response:
projectId = req.args.get("projectId")
prompt = req.args.get("prompt")
if projectId is None:
return https_fn.Response("No projectId", status=400)
if prompt is None:
return https_fn.Response("No projectId", status=400)
llm = OpenAI(temperature=0)
print(llm(prompt))
return https_fn.Response(f"Success!", status=200) `
@jhuleatt Do you mind sharing your fix? This is not working for me:
import os os.environ['OBJC_DISABLE_INITIALIZE_FORK_SAFETY'] = 'YES'
Starting the emulator with this option does the trick for me:
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
@jhuleatt Could you provide a reproducible example so that I may test this further?
I'm running into the same issue.
To repro, create a new Firebase Function module (using firebase init functions
, and then change the code for on_request_example
like this:
import requests
@https_fn.on_request()
def on_request_example(req: https_fn.Request) -> https_fn.Response:
response = requests.get("https://www.google.com")
return https_fn.Response("Hello world!")
This results in the following output:
⬢ functions: Failed to handle request for function us-central1-on_request_example
⬢ functions: Failed to start functions in helloworld: Error: socket hang up
Hello @peterfriese. Unfortunately, I am not able to reproduce this issue. I tried the following code:
import requests
from firebase_functions import https_fn, options
from firebase_admin import initialize_app
options.set_global_options(max_instances=10)
initialize_app()
@https_fn.on_request()
def on_request_example(req: https_fn.Request) -> https_fn.Response:
response = requests.get("https://www.example.com") # Tried with google.com as well
return https_fn.Response("Hello world!")
The following is my requirements.txt
:
firebase-functions==0.1.1
My python version is Python 3.11.4
Solved same kind of error by overwriting the unused function.
import requests
@https_fn.on_request()
def the_deleted_function_name(req: https_fn.Request) -> https_fn.Response:
pass
It seems emulator tries to find cached function that doesn't exist.
@exaby73
Unfortunately, I am not able to reproduce this issue. I tried the following code:
Did you try on a Mac? I think I'm also using that OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
@antont I am on an M1 mac, without the OBJC_DISABLE_INITIALIZE_FORK_SAFETY
flag set
@exaby73 I am on an M1 mac, without the
OBJC_DISABLE_INITIALIZE_FORK_SAFETY
flag set
Ok. After OS upgrade and related restart, I didn't have the env var back yet, and again got that:
> objc[26098]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
> objc[26098]: +[__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.
i Request to function failed: Error: socket hang up
Then setting the flag fixed it.
I'll keep this env now so can provide details about versions etc. later if that helps.
Hey @antont. I'm wondering if you can reproduce this using Node as well. Since I can't reproduce this myself, I am unable to confirm it
Hey @jhuleatt. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@jhuleatt if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.
Exporting those two variables fixed the problem for me:
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
export no_proxy=*
Still an issue with me and my M1 Mac.
Going to try a couple of the fixes, don't really have a short example to reproduce.
EDIT: export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES Allowed the emulator python cloud function to work
Is this now documented somewhere?
Am I correct to summarize this as:
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
in order for the (Python engine ??) to run properlyAm I correct to summarize this as:
- MacOS
- M1 chip (M2? M3? Intel?)
- running Python cloud functions in the Emulator Suite
- need to set env var
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
in order for the (Python engine ??) to run properly
Yes that is correct, at least for my case (Macbook Air, M1, 2020) Until I set that export, I was unable to have my python cloud functions run successfully in the Firebase Emulator.
On my m1 mac, I get the following error when emulating a function with the BigQuery python SDK:
here's the function code: