Commits

Aristarkh Zagorodnikov committed 54cc8e6

Connections are returned to pool earlier to prevent hammering the server with reconnects after failure

Comments (0)

Files changed (1)

gridfs/mod_gridfs.cpp

 					apr_table_setn(request->headers_out, "ETag", md5.c_str());
 				if (ap_meets_conditions(request) == HTTP_NOT_MODIFIED)
 				{
+					connection->done();
 					if (!md5.empty())
 						apr_table_unset(request->headers_out, "ETag");
-					connection->done();
 					return HTTP_NOT_MODIFIED;
 				}
 				const mongo::gridfs_offset file_length = gridfile.getContentLength();
 					const int num_chunks = gridfile.getNumChunks();
 					if (num_chunks == 0)
 					{
+						connection->done();
 						ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, request, "mod_gridfs: No chunks available for file '%s'.", filename); 
-						connection->done();
 						return HTTP_INTERNAL_SERVER_ERROR;
 					}
 					brigade = apr_brigade_create(request->pool, request->connection->bucket_alloc);
 					if (brigade == 0)
 					{
+						connection->done();
 						ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, request, "mod_gridfs: Failed to create brigade."); 
-						connection->done();
 						return HTTP_INTERNAL_SERVER_ERROR;
 					}
 					for (int chunk_index = 0;chunk_index < num_chunks;chunk_index++) 
 							continue;
 						if ((result = apr_brigade_write(brigade, 0, 0, chunk_data, chunk_length)) != APR_SUCCESS)
 						{
+							connection->done();
 							ap_log_rerror(APLOG_MARK, APLOG_ERR, result, request, "mod_gridfs: Failed to write chunk %d for file '%s' to brigade (length: %d).", chunk_index, filename, chunk_length); 
-							connection->done();
 							apr_brigade_destroy(brigade);
 							brigade = 0;
 							return HTTP_INTERNAL_SERVER_ERROR;
 					}
 					if (content_length != file_length)
 					{
+						connection->done();
 						ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, result, request, "mod_gridfs: Mismatching files/chunks length for file '%s' (difference: %d).", filename, static_cast<int>(file_length - content_length));
-						connection->done();
 						apr_brigade_destroy(brigade);
 						brigade = 0;
 						return HTTP_INTERNAL_SERVER_ERROR;
 				case 10009:	//	ReplicaSetMonitor no master found for set
 				case 10276:	//	DBClientBase::findN: transport error
 				case 11002:	//	pool socket exception
+					connection->kill();
 					ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, result, request, "mod_gridfs: Retrying after MongoDB exception for file '%s' (code: %d): %s.", filename, code, exception.what()); 
 					break;