diff --git a/README.rst b/README.rst index d39899a..af86bc1 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,10 @@ +Unmaintained +============ +Note this is an unmaintained fork of Mike's original (also unmaintained) repo. +I've done /some/ work on it - namely solving the problem of stale sockets if mongodb restarts, as well as integrating some other pull requests that weren't in the original - +but last time I tried this module wouldn't compile against latest version of nginx (1.5.7). +I've since abandoned this approach, in favour of the node server here: https://github.com/rdkls/node-gridfs-http-frontend so won't be spending any more time trying to get it working. It's not far off though ... + nginx-gridfs ============ :Authors: diff --git a/ngx_http_gridfs_module.c b/ngx_http_gridfs_module.c index f7dc7bb..85097ec 100644 --- a/ngx_http_gridfs_module.c +++ b/ngx_http_gridfs_module.c @@ -888,26 +888,6 @@ static ngx_int_t ngx_http_gridfs_handler(ngx_http_request_t* request) { // ---------- RETRIEVE GRIDFILE ---------- // - do { - e = FALSE; - status = gridfs_init(&mongo_conn->conn, - (const char*)gridfs_conf->db.data, - (const char*)gridfs_conf->root_collection.data, - &gfs); - if (status != MONGO_OK) { - e = TRUE; ecounter++; - if (ecounter > MONGO_MAX_RETRIES_PER_REQUEST - || ngx_http_mongo_reconnect(request->connection->log, mongo_conn) == NGX_ERROR - || ngx_http_mongo_reauth(request->connection->log, mongo_conn) == NGX_ERROR) { - ngx_log_error(NGX_LOG_ERR, request->connection->log, 0, - "Mongo connection dropped, could not reconnect"); - if(mongo_conn->conn.connected) { mongo_disconnect(&mongo_conn->conn); } - free(value); - return NGX_HTTP_SERVICE_UNAVAILABLE; - } - } - } while (e); - bson_init(&query); switch (gridfs_conf->type) { case BSON_OID: @@ -923,16 +903,30 @@ static ngx_int_t ngx_http_gridfs_handler(ngx_http_request_t* request) { } bson_finish(&query); - status = gridfs_find_query(&gfs, &query, &gfile); + do { + e = FALSE; + if (gridfs_init(&mongo_conn->conn, + (const char*)gridfs_conf->db.data, + (const char*)gridfs_conf->root_collection.data, + &gfs) != MONGO_OK + || (status = gridfs_find_query(&gfs, &query, &gfile) == MONGO_ERROR)) { + e = TRUE; ecounter++; + if (ecounter > MONGO_MAX_RETRIES_PER_REQUEST + || ngx_http_mongo_reconnect(request->connection->log, mongo_conn) == NGX_ERROR + || ngx_http_mongo_reauth(request->connection->log, mongo_conn) == NGX_ERROR) { + ngx_log_error(NGX_LOG_ERR, request->connection->log, 0, + "Mongo connection dropped, could not reconnect"); + if(&mongo_conn->conn.connected) { mongo_disconnect(&mongo_conn->conn); } + bson_destroy(&query); + free(value); + return NGX_HTTP_SERVICE_UNAVAILABLE; + } + } + } while (e); bson_destroy(&query); free(value); - if(status == MONGO_ERROR) { - gridfs_destroy(&gfs); - return NGX_HTTP_NOT_FOUND; - } - /* Get information about the file */ length = gridfile_get_contentlength(&gfile); numchunks = gridfile_get_numchunks(&gfile);