James Allen
James Allen

Reputation: 7169

What does "Bad file descriptor" mean in the context of uploading files?

I have a strange Bad file descriptor error with some users when performing a resumable upload using Google Drive API in dart using the http package. The issue only seems to affect certain users of my app in the wild, and I can't seem to replicate it, so I'm hoping for a bit of advice on what the error message means to help me figure out what's going on.

I'm following the docs to update a file:

This works fine for me, and the majority of users. However I'm getting error reports from some users for the last part (the PUT), and the only message it contains is Bad file descriptor.

I'm completely at a loss as to what this means.

I've checked that the file matches it's mime type (I send two types of file, text/plain and application/gzip, I've had this error for both), it definitely matches (at least in all my tests).

The only thing that changes for users in the wild is the contents of the text files and GZips. I've checked the first few bytes of the GZips when the error is caught, they match the GZip specification for members perfectly so they seem to be valid files.

Can anyone suggest what Bad file descriptor might mean, or where the problem may lie? Googling this results in no results at all, and I can't find any documentation on this error.

UPDATE

This turned out to be an issue with the http package and nothing to do with Google Drive. It's a little unclear but it seems to happen sometimes if the connection is dropped or the device is locked, and mainly seems to affect iOS (although I've also had the same error for some Android users). So it seems that Bad file descriptor (thanks @jats-ppg for explaining) usually means it's trying to access something that doesn't exist or that it doesn't have permission to access. So in this context, my best guess is that something happens (eg the device is locked) just before during upload which means the package loses access to the file it's trying to upload.

A suggested workaround documented in the issue which seems to mostly resolve the problem in iOS is to use the cupertino_http client implementation for iOS instead of the default implementation, which you can configure by following the instructions in the package readme.

Upvotes: 0

Views: 57

Answers (1)

Jats PPG
Jats PPG

Reputation: 790

Recap: Bad File Discriptor Error

Some users are getting a Bad file descriptor error when uploading files to Google Drive. The uploads mostly work, but this error happens for a few users. OP finds out that the error is nothing to do with Google Drive but more on the library they are using.

Based on my experience, this error is usually related to file access. As mentioned in the comments, it can occur when the program attempts to access a file that either doesn't exist or for which it lacks the necessary permissions.

@James Allen clarified that the problem isn't with Google Drive, but with the misleading error message from the http library being used.

Upvotes: 1

Related Questions