AmazonS3:收到警告:S3AbortableInputStream:并非从S3ObjectInputStream读取所有字节,从而中止HTTP连接 [英] AmazonS3: Getting warning: S3AbortableInputStream:Not all bytes were read from the S3ObjectInputStream, aborting HTTP connection

查看:1688
本文介绍了AmazonS3:收到警告:S3AbortableInputStream:并非从S3ObjectInputStream读取所有字节,从而中止HTTP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我得到的警告:

S3AbortableInputStream:并非从S3ObjectInputStream读取所有字节,从而中止HTTP连接.这可能是一个错误,并且可能导致次佳的行为.通过远程GET仅请求所需的字节,或在使用后耗尽输入流.

S3AbortableInputStream:Not all bytes were read from the S3ObjectInputStream, aborting HTTP connection. This is likely an error and may result in sub-optimal behavior. Request only the bytes you need via a ranged GET or drain the input stream after use.

我尝试对资源使用try,但是S3ObjectInputStream似乎无法通过此方法关闭.

I tried using try with resources but S3ObjectInputStream doesn't seem to close via this method.

 try (S3Object s3object = s3Client.getObject(new GetObjectRequest(bucket, key));
      S3ObjectInputStream s3ObjectInputStream = s3object.getObjectContent();
      BufferedReader reader = new BufferedReader(new InputStreamReader(s3ObjectInputStream, StandardCharsets.UTF_8));
    ){
  //some code here blah blah blah
 }

我还尝试了下面的代码并明确关闭,但这也不起作用:

I also tried below code and explicitly closing but that doesn't work either:

S3Object s3object = s3Client.getObject(new GetObjectRequest(bucket, key));
S3ObjectInputStream s3ObjectInputStream = s3object.getObjectContent();

try (BufferedReader reader = new BufferedReader(new InputStreamReader(s3ObjectInputStream, StandardCharsets.UTF_8));
){
     //some code here blah blah
     s3ObjectInputStream.close();
     s3object.close();
}

任何帮助将不胜感激.

PS:我只从S3中读取文件的两行,并且文件中有更多数据.

PS: I am only reading two lines of the file from S3 and the file has more data.

推荐答案

通过其他媒介获得答案.在这里分享:

Got the answer via other medium. Sharing it here:

该警告表明您调用了close()而不读取整个文件.这是有问题的,因为S3仍在尝试发送数据,而您使连接处于悲哀状态.

The warning indicates that you called close() without reading the whole file. This is problematic because S3 is still trying to send the data and you're leaving the connection in a sad state.

这里有两个选项:

  1. 从输入流中读取其余数据,以便可以重新使用连接.
  2. 调用s3ObjectInputStream.abort()关闭连接而不读取数据.该连接将不会被重用,因此在下一个重新创建连接的请求中,您的性能受到了影响.如果要花很长时间才能读取文件的其余部分,这可能是值得的.

这篇关于AmazonS3:收到警告:S3AbortableInputStream:并非从S3ObjectInputStream读取所有字节,从而中止HTTP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆