firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Emulator error `Error: socket hang up`

Open jhuleatt opened this issue 1 year ago • 19 comments

On my m1 mac, I get the following error when emulating a function with the BigQuery python SDK:

>  objc[122]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
>  objc[122]: +[__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.
⬢  functions: Failed to handle request for function us-central1-commontrees
⬢  functions: Failed to start functions in /Users/jhuleatt/projects/io-python/functions: Error: socket hang up

here's the function code:

from firebase_functions import https_fn
from google.cloud import bigquery
import json

@https_fn.on_request(timeout_sec=20)
def commontrees(req: https_fn.Request) -> https_fn.Response:
    client = bigquery.Client()
    query = """
        SELECT spc_latin, spc_common, COUNT(spc_latin) as num_specimens
        FROM `bigquery-public-data.new_york_trees.tree_census_2015`
        WHERE SPC_LATIN <> ''
        GROUP BY spc_latin, spc_common
        ORDER BY num_specimens DESC
        LIMIT 50
    """
    query_job = client.query(query)

    common_trees = [];
    for row in query_job:
        common_trees.append({
            "scientificName": row['spc_latin'],
            "commonName": row['spc_common'],
            "count": row['num_specimens']
        })
    return https_fn.Response(json.dumps(common_trees),  mimetype='application/json')

jhuleatt avatar Mar 06 '23 18:03 jhuleatt