Reputation: 7169
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:
https://www.googleapis.com/upload/drive/v3/files/<some file ID>?uploadType=resumable
to get the upload URI, with an empty JSON dictionary ({}
) as the body (because no metadata needs updating), and the required headers (X-Upload-Content-Type
set to the mime type, X-Upload-Content-Length
set to the size of the file in bytes, Content-Type
set to application/json; charset=UTF-8
and Content-Length
set to the size of the empty json body). This always succeeds fine.location
header in the response (which is something like https://www.googleapis.com/upload/drive/v3/files/<some file ID>?uploadType=resumable&upload_id=<a long string>
)Content-Length
set to the length of the fileThis 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'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
Reputation: 790
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