[CDRIVER-2566] Server error ignored during GridFS chunk upload Created: 23/Mar/18  Updated: 28/Oct/23  Resolved: 23/Jul/18

Status: Closed
Project: C Driver
Component/s: GridFS
Affects Version/s: None
Fix Version/s: 1.13.0

Type: Bug Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Found by Jeroenooms, possible bug in the C Driver's GridFS implementation. Using a free mLab account, uploading a 3.5MB file silently fails. The fs.files document is written with "length" equal to one chunk (255k), and no chunk is written at all. The GridFS API appears to return a success, however.

This seems related to mLab storage limits. Once we dropped the database, uploads worked correctly.

Either:
1. The C Driver ignores an error that it should report when chunk-upload fails
2. Jeroen's use of the C Driver ignores an error
3. mLab acts weird when it a write would exceed the storage limit

Jeroen, could you paste the C code that uploads a file and checks for error please?

Update: #1 is correct. mongoc_gridfs_create_file_from_stream() ignores errors from mongoc_gridfs_file_writev while uploading chunks. I imagine that if an mLab user is too close to quota to save a chunk but still has space left for the fs.files record, that mongoc_gridfs_file_writev fails silently and mongoc_gridfs_file_save succeeds.



 Comments   
Comment by Githook User [ 23/Jul/18 ]

Author:

{'username': 'ajdavis', 'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com'}

Message: CDRIVER-2566 check errors writing to gridfs file
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/abe41c851f17e8cc8f73542820c4c153e4cc8564

Comment by Jeroen Ooms [X] [ 23/Mar/18 ]

Below cleaned up code (removed R specific API calls). I am checking mongoc_gridfs_file_save() return value and even get a valid ID back.

  mongoc_gridfs_t *fs; // get the gridfs pointer from R
  mongoc_stream_t * stream = mongoc_stream_file_new_for_path("filename.bin", O_RDONLY, 0);
  if(stream == NULL)
    stop("Failure at mongoc_stream_file_new_for_path()");
 
  mongoc_gridfs_file_opt_t opt = {0};
  opt.filename = "filename.bin";
  mongoc_gridfs_file_t * file = mongoc_gridfs_create_file_from_stream (fs, stream, &opt);
  if(file == NULL)
    stop("Failure at mongoc_gridfs_create_file_from_stream()");
  if(!mongoc_gridfs_file_save (file)){
    bson_error_t err;
    mongoc_gridfs_file_error(file, &err);
    stop(err.message);
  }
  bson_t val;
  bson_init (&val);
  BSON_APPEND_VALUE(&val, "id", mongoc_gridfs_file_get_id(file));
  mongoc_gridfs_file_destroy (file);
  return val;

Generated at Wed Feb 07 21:15:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.