From 29fe3449b35bcf5fcf5cbab3189b2f0b61304585 Mon Sep 17 00:00:00 2001 From: Krishna Srinivas Date: Thu, 2 Nov 2017 15:13:59 -0700 Subject: [PATCH] Drain out empty response to close the connection fixes #640 --- src/main/minio.js | 48 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/main/minio.js b/src/main/minio.js index 44de8bf43..fea3d4ea0 100644 --- a/src/main/minio.js +++ b/src/main/minio.js @@ -522,7 +522,10 @@ export class Client { var headers = {} // virtual-host-style request but signed with region 'us-east-1' // makeBucket request has to be always signed bye 'us-east-1' - this.makeRequest({method, bucketName, headers}, payload, 200, 'us-east-1', (e) => { + this.makeRequest({method, bucketName, headers}, payload, 200, 'us-east-1', (e, response) => { + if (!e) { + response.on('data', ()=>{}) + } if (e && e.name === 'AuthorizationHeaderMalformed') { // if the bucket already exists in non-standard location we try again // by signing the request with the correct region and S3 returns: @@ -637,7 +640,12 @@ export class Client { throw new TypeError('callback should be of type "function"') } var method = 'HEAD' - this.makeRequest({method, bucketName}, '', 200, '', cb) + this.makeRequest({method, bucketName}, '', 200, '', (e, response) => { + if (!e) { + response.on('data', ()=>{}) + } + cb(e) + }) } // Remove a bucket. @@ -653,9 +661,12 @@ export class Client { throw new TypeError('callback should be of type "function"') } var method = 'DELETE' - this.makeRequest({method, bucketName}, '', 204, '', (e) => { + this.makeRequest({method, bucketName}, '', 204, '', (e, response) => { // If the bucket was successfully removed, remove the region map entry. - if (!e) delete(this.regionMap[bucketName]) + if (!e) { + delete(this.regionMap[bucketName]) + response.on('data', ()=>{}) + } cb(e) }) } @@ -688,7 +699,12 @@ export class Client { cb => { var method = 'DELETE' var query = `uploadId=${removeUploadId}` - this.makeRequest({method, bucketName, objectName, query}, '', 204, '', e => cb(e)) + this.makeRequest({method, bucketName, objectName, query}, '', 204, '', (e, response) => { + if (!e) { + response.on('data', ()=>{}) + } + cb(e) + }) }, cb ) @@ -1364,6 +1380,7 @@ export class Client { var method = 'HEAD' this.makeRequest({method, bucketName, objectName}, '', 200, '', (e, response) => { if (e) return cb(e) + response.on('data', () => {}) var result = { size: +response.headers['content-length'], contentType: response.headers['content-type'], @@ -1395,7 +1412,12 @@ export class Client { throw new TypeError('callback should be of type "function"') } var method = 'DELETE' - this.makeRequest({method, bucketName, objectName}, '', 204, '', cb) + this.makeRequest({method, bucketName, objectName}, '', 204, '', (e, response) => { + if (!e) { + response.on('data', ()=>{}) + } + cb(e) + }) } // Get the policy on a bucket or an object prefix. @@ -1470,7 +1492,12 @@ export class Client { policyPayload = JSON.stringify(policyPayload) } - this.makeRequest({method, bucketName, query}, policyPayload, 204, '', cb) + this.makeRequest({method, bucketName, query}, policyPayload, 204, '', (e, response) => { + if (!e) { + response.on('data', ()=>{}) + } + cb(e) + }) } // Generate a generic presigned URL which can be @@ -1956,7 +1983,12 @@ export class Client { var query = 'notification' var builder = new xml2js.Builder({rootName:'NotificationConfiguration', renderOpts:{'pretty':false}, headless:true}) var payload = builder.buildObject(config) - this.makeRequest({method, bucketName, query}, payload, 200, '', cb) + this.makeRequest({method, bucketName, query}, payload, 200, '', (e, response) => { + if (!e) { + response.on('data', ()=>{}) + } + cb(e) + }) } removeAllBucketNotification(bucketName, cb) {