Cloud Functions がステータス 500 を返し、レジストリに表示されない

Cloud Functions がステータス 500 を返し、レジストリに表示されない

奇妙な動作が発生しています。Firebase Cloud Functions にいくつかの http 関数があります。これらは完璧に動作しますが、しばらくの間ステータス 500 を返し、その後数分間正常に動作し、その後再びステータス 500 を返す日があり、この動作は 1 日中続きます。

最も奇妙なのは、スタック ドライバーでエラー メッセージが表示されないことです。実際、これらの呼び出しに関するレジストリは存在しません。呼び出しが何らかの理由で Google のサービスに到達しないか、単に拒否されて、それに関するレジストリが存在しないかのようです。

私のアプリケーションで最もよく使用される関数の 1 つを実装したものを投稿します。

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

admin.initializeApp()

exports.changeOrderStatus_1 = functions.https.onRequest((request, response) =>
{
    //Check Headers
    const clientID = request.get('ClientID');

    if(clientID === null || clientID === undefined || clientID === "")
    {
        console.error(new Error('clientID not provided.'));
        return response.status(500).send('clientID not provided.');
    }

    const unitID = request.get('UnitID');

    if(unitID === null || unitID === undefined || unitID === "")
    {
        console.error(new Error('unitID not provided.'));
        return response.status(500).send('unitID not provided.');
    }

    //Check body
    const orderID = request.body.OrderID;

    if(orderID === null || orderID === undefined || orderID === "")
    {
        console.error(new Error('orderID not provided.'));
        return response.status(500).send('orderID not provided.');
    }

    const orderStatus = request.body.OrderStatus;

    if(orderStatus === null || orderStatus === undefined || orderStatus === "")
    {
        console.error(new Error('orderStatus not provided.'));
        return response.status(500).send('orderStatus not provided.');
    }

    const orderStatusInt = Number.parseInt(String(orderStatus));

    const notificationTokenString = String(request.body.NotificationToken);

    const customerID = request.body.CustomerID;

    const promises: any[] = [];

    const p1 = admin.database().ref('Clients/' + clientID + '/UnitData/'+ unitID +'/FreshData/Orders/' + orderID + '/Status').set(orderStatusInt);

    promises.push(p1);

    if(notificationTokenString !== null && notificationTokenString.length !== 0 && notificationTokenString !== 'undefined' && !(customerID === null || customerID === undefined || customerID === ""))
    {
        const p2 = admin.database().ref('Customers/' + customerID + '/OrderHistory/' + orderID + '/Status').set(orderStatusInt);

        promises.push(p2);

        if(orderStatusInt > 0 && orderStatusInt < 4)
        {
            const p3 = admin.database().ref('Customers/' + customerID + '/ActiveOrders/' + orderID).set(orderStatusInt);

            promises.push(p3);
        }
        else
        {
            const p4 = admin.database().ref('Customers/' + customerID + '/ActiveOrders/' + orderID).set(null);

            promises.push(p4);
        }

        let title = String(request.body.NotificationTitle);
        let message = String(request.body.NotificationMessage);

        if(title === null || title.length === 0)
            title = "?????";

        if(message === null || message.length === 0)
            message = "?????";

        const payload = 
        {
            notification:
            {
                title: title,
                body: message,
                icon: 'notification_icon',
                sound : 'default'
            }
        };

        const p5 = admin.messaging().sendToDevice(notificationTokenString, payload);

        promises.push(p5);
    }

    return Promise.all(promises).then(r => { return response.status(200).send('success') })
        .catch(error => 
            {
                console.error(new Error(error));
                return response.status(500).send(error)
            });
})

これは私がそれを呼び出す方法です。クライアント アプリケーションは、C# 言語を使用して Xamarin Forms アプリで実行されます。

        static HttpClient Client;

        public static void Initialize()
        {
            Client = new HttpClient();
            Client.BaseAddress = new Uri("My cloud functions adress");
            Client.DefaultRequestHeaders.Add("UnitID", UnitService.GetUnitID());
            Client.DefaultRequestHeaders.Add("ClientID", AuthenticationService.GetFirebaseAuth().User.LocalId);
        }

  public static async Task<bool> CallChangeOrderStatus(OrderHolder holder, int status)
        {
            Debug.WriteLine("CallChangeOrderStatus: " + status);

            try
            {
                var content = new Dictionary<string, string>();

                content.Add("OrderID", holder.Order.ID);
                content.Add("OrderStatus", status.ToString());
                
                if (!string.IsNullOrEmpty(holder.Order.NotificationToken) && NotificationService.ShouldSend(status))
                {
                    content.Add("CustomerID", holder.Order.SenderID);
                    content.Add("NotificationToken", holder.Order.NotificationToken);
                    content.Add("NotificationTitle", NotificationService.GetTitle(status));
                    content.Add("NotificationMessage", NotificationService.GetMessage(status));
                }

                var result = await Client.PostAsync("changeOrderStatus_1", new FormUrlEncodedContent(content));

                return result.IsSuccessStatusCode;
            }
            catch (HttpRequestException exc)
            {
#if DEBUG
                ErrorHandlerService.ShowErrorMessage(exc);
#endif
                Crashes.TrackError(exc);

                return false;
            }
        }

これらの関数は 1 分間に数回呼び出されますが、呼び出されない状態が最大 1 時間続くこともあります。

モバイル接続、Wi-Fi 接続、有線接続、さまざまなインターネット プロバイダーからリクエストを送信しましたが、それでも問題は発生します。

何か間違ったことをしているのでしょうか?何か見落としているのでしょうか?Google サーバーが不安定なのでしょうか?

答え1

昨日は既知の問題が発生しました、私はCloud Functionsで同じ現象を経験し、サポートチームからこの情報が提供されました。それでも問題が解決しない場合は、GCP サポート チームあなたのプロジェクトを注意深く検査し、それについてさらにアドバイスを提供するためです:)

関連情報