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

Thumbnails example - ECONNRESET #107

Closed
mrp14 opened this issue Apr 5, 2017 · 13 comments
Closed

Thumbnails example - ECONNRESET #107

mrp14 opened this issue Apr 5, 2017 · 13 comments

Comments

@mrp14
Copy link
Contributor

mrp14 commented Apr 5, 2017

Hello,

I developed something really close to Thumbnails example provided here, and sometimes (often) I'm getting this error when uploading or deleting files from Storage :

Error: read ECONNRESET
    at exports._errnoException (util.js:1026:11)
    at TLSWrap.onread (net.js:569:26)

I found #78, but I checked that a promise is returned everytime.
Here is some code snippet, for the deletion part :

index.js

exports.exampleFunction = functions.storage.object().onChange(event => {
    return f_thumbnails.exampleFunction(event);
});

example_function.js

module.exports = exports = function (_admin, _config) {
    admin = _admin;
    config = _config;

    return {
        "exampleFunction": function (event) {
            return exampleFunction(event);
        }
    };
};

const exampleFunction = function (event) {
    const gcsSourceFilePath = event.data.name;
    const gcsSourceFilePathSplit = gcsSourceFilePath.split('/');
    const gcsBaseFolder = gcsSourceFilePathSplit.length > 0 ? gcsSourceFilePathSplit[0] : '';
    const gcsSourceFileName = gcsSourceFilePathSplit.pop();
    const gceSourceFileDir = gcsSourceFilePathSplit.join('/') + (gcsSourceFilePathSplit.length > 0 ? '/' : '');

    // Not an image
    if (!event.data.contentType.startsWith('image/')) {
        console.log('Not an image !');
        return;
    }

    // Thumbnail
    if (gcsSourceFileName.startsWith(config.IMAGES_THUMBNAIL_PREFIX)) {
        console.log('Thumbnail !');
        return;
    }

    const bucket = gcs.bucket(event.data.bucket);
    const gcsThumbnailFilePath = gceSourceFileDir + config.IMAGES_THUMBNAIL_PREFIX + gcsSourceFileName;


    // File deletion
    if (event.data.resourceState === 'not_exists') {
        console.log('Thumbnail deletion : ' + gcsThumbnailFilePath);
        return bucket.file(gcsThumbnailFilePath).delete().then(() => {
            console.log('Deleted thumbnail ' + gcsThumbnailFilePath);
        });
    }
    ...

I also created this StackOverflow post.

Thanks.

@nicolasgarnier
Copy link
Contributor

Let's handle that on StackOverflow :)

@martemorfosis
Copy link

martemorfosis commented Apr 19, 2017

@nicolasgarnier This was happening to me too. Filed bug report [0-1088000016633] ECONNRESET Error happens randomly and halts function execution. Tried to deploy the function again but run into a couple more issues:

  • 1st a FCF that triggered on Storage suddenly was refusing to deploy until I manually added:
"Project editors-xxxxxxxxxx Owner"

To the Bucket permissions on Google Cloud Console.

  • 2nd Now I'm getting this error when it fires:
    at Object.parseHttpRespMessage (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:156:33)
    at Object.handleResp (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:131:18)
    at Duplexify.<anonymous> (/user_code/node_modules/@google-cloud/storage/src/file.js:724:21)
    at emitOne (events.js:96:13)
    at Duplexify.emit (events.js:188:7)
    at emitOne (events.js:96:13)
    at DestroyableTransform.emit (events.js:188:7)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at Request.<anonymous> (/user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:1108:14)

Seems to be authentication related, but this was working fine a few days ago. Any ideas?

@chris-metz
Copy link

Yes, I really think this is an open issue as I can confirm the problem. My function sometimes runs completely and sometimes throws this error.
Mine also is close to / derived from the provided image convert example.

@asciimike
Copy link

@martemorfosis and @Chris-mE

The issue appears to be related to bucket and object ACLs not being set up properly. Here's a bash script (using the gsutil tool, available here):

#! /bin/bash
PROJECT = "<your-project-id>"
BUCKET = "<your-bucket-name>"

# Set bucket ACLs
# This will enable storage functions to deploy again
gsutil -m acl ch -p owners-$PROJECT:O gs://$BUCKET
gsutil -m acl ch -p editors-$PROJECT:O gs://$BUCKET
gsutil -m acl ch -p viewers-$PROJECT:R gs://$BUCKET

# Set default object/bucket ACLs
# This makes it so any new objects added have the proper ACLs
gsutil defacl ch -p owners-$PROJECT:O gs://$BUCKET
gsutil defacl ch -p editors-$PROJECT:O gs://$BUCKET
gsutil defacl ch -p viewers-$PROJECT:R gs://$BUCKET

# Recursively set object ACLs
# This will fix all existing objects if any are broken
gsutil -m acl -r ch -p owners-$PROJECT:O gs://$BUCKET
gsutil -m acl -r ch -p editors-$PROJECT:O gs://$BUCKET
gsutil -m acl -r ch -p viewers-$PROJECT:R gs://$BUCKET

@chris-metz
Copy link

@mcdonamp I never used gsutil, just want to use Firebase functions as described in this repo :-) For the understanding: can you tell me if this is some bug at Firebase Beta (that will be fixed somewhen in the future), or where does this error occurs from? At the moment the functions are not useable for me as sometimes it works, and sometimes it just throws this error:

Error: read ECONNRESET
at exports._errnoException (util.js:1026:11)
at TLSWrap.onread (net.js:569:26)

@katowulf
Copy link

How your bucket ended up in a bad state is unclear at this point. Mike is investigating.

The solution is to follow Mike's instructions and run gsutil commands he's provided.

@inlined
Copy link
Member

inlined commented Apr 25, 2017

I think the ECONNRESET issue is an issue in the google-cloud-node module and have filed googleapis/google-cloud-node#2254 to escalate.

@inlined inlined reopened this Apr 25, 2017
@mrp14
Copy link
Contributor Author

mrp14 commented Apr 25, 2017

IMO, it seems to be related to Google Storage servers. When it comes up, every call ends up as ECONNRESET for several minutes. For example, yesterday 4 calls between 8:16PM and 8:23PM (UTC+2) crashed, while 5 successive calls this morning finished with no errors.

Another point, to join @inlined remark and issue, is that it only happens when using google-cloud-node. I never had any problem uploading files to Storage client-side, using iOS or Android Firebase SDK, even during the moments all server calls (Firebase functions with google-cloud-node) do ECONNRESET.

@chris-metz
Copy link

@mcdonamp yes of course, thank you for looking into this.

I can also confirm never have any problems handling files client side (JS / Web SDK)

@mrp14
Copy link
Contributor Author

mrp14 commented Apr 26, 2017

Someone on SO linked this : https://issuetracker.google.com/issues/36667671
Visibly we just have to wait for a new release of google-cloud-node, or use this patch

If someone can confirm this is working (can't try this out today)

@Belindachenhj
Copy link

Belindachenhj commented Apr 28, 2017

I did all the things above, but still get this error sometimes, why it's not stable?

@katowulf
Copy link

If you did all the things above, then surely you read about the bug in the public issue, and also noted the patch?

Closing this issue to prevent further "me too" discussions. Follow the public bug and file separate issues as needed.

@firebase firebase locked and limited conversation to collaborators Apr 28, 2017
@nicolasgarnier
Copy link
Contributor

Thanks @katowulf yes it seems this was fixed in googleapis/google-cloud-node#2254 Closing now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants