将文件上传到Blob容器似乎泄漏了频道

时间:2019-06-17 16:36:51

标签: java azure-storage azure-storage-blobs

我是Azure的新手,我正在将azure-storage-blob v11.0.0用于Java,并按照此处的示例https://github.com/Azure-Samples/storage-blob-java-getting-started

尝试上传文件

这是按预期方式上传的,但是我的应用程序仍然处于活动状态,似乎存在远程套接字超时,这将导致生成和异常:

18:16:46.528 23751 [nioEventLoopGroup-1-1] INFO  com.microsoft.azure.storage.blob.LoggingFactory$LoggingPolicy - Successfully Received Response
Request try:'1', request duration:'1271' ms, operation duration:'1271' ms
PUT: https://REDACTED.blob.core.windows.net/REDACTED/REDACTED.wav
Authorization: REDACTED
Content-Length: 275244
x-ms-version: 2018-11-09
x-ms-date: Mon, 17 Jun 2019 16:16:45 GMT
host: REDACTED.blob.core.windows.net
Content-Type: application/octet-stream
connection: keep-alive
x-ms-client-request-id: c78bf188-f604-40da-b5a9-340eaad045bd
x-ms-blob-type: BlockBlob
User-Agent:  Azure-Storage/11.0.0 (JavaJRE 1.8.0_212; Linux 4.19.49-1-MANJARO)

18:16:46.540 23763 [nioEventLoopGroup-1-1] DEBUG AzureCopy - Completed upload request. : 201
18:16:46.541 23764 [nioEventLoopGroup-1-1] DEBUG com.microsoft.rest.v2.http.SharedChannelPool - Channel released to pool: 77156491
18:19:48.496 205719 [nioEventLoopGroup-1-2] WARN  com.microsoft.rest.v2.http.NettyClient$AcquisitionListener - Error emitted on channel 8afa7171. Message: Connexion ré-initialisée par le correspondant
18:19:48.500 205723 [nioEventLoopGroup-1-2] DEBUG com.microsoft.rest.v2.http.NettyClient$AcquisitionListener - Stack trace: 
java.lang.Exception: null
    at com.microsoft.rest.v2.http.NettyClient$AcquisitionListener.emitError(NettyClient.java:427)
    at com.microsoft.rest.v2.http.NettyClient$HttpClientInboundHandler.exceptionCaught(NettyClient.java:890)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:297)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:276)
    at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:268)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireExceptionCaught(CombinedChannelDuplexHandler.java:426)
    at io.netty.channel.ChannelHandlerAdapter.exceptionCaught(ChannelHandlerAdapter.java:92)
    at io.netty.channel.CombinedChannelDuplexHandler$1.fireExceptionCaught(CombinedChannelDuplexHandler.java:147)
    at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:143)
    at io.netty.channel.CombinedChannelDuplexHandler.exceptionCaught(CombinedChannelDuplexHandler.java:233)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:297)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:276)
    at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:268)
    at io.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:1098)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:297)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:276)
    at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:268)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.exceptionCaught(DefaultChannelPipeline.java:1375)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:297)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:276)
    at io.netty.channel.DefaultChannelPipeline.fireExceptionCaught(DefaultChannelPipeline.java:918)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.handleReadException(AbstractNioByteChannel.java:125)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:174)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:682)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:617)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:534)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:906)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:748)
18:19:48.501 205724 [nioEventLoopGroup-1-2] INFO  com.microsoft.rest.v2.http.SharedChannelPool - ---- com.microsoft.rest.v2.http.SharedChannelPool@fbece82: size 768, keep alive (sec) 60 ----
18:19:48.502 205725 [nioEventLoopGroup-1-2] INFO  com.microsoft.rest.v2.http.SharedChannelPool - Channel    State   For Age URL
18:19:48.504 205727 [nioEventLoopGroup-1-2] INFO  com.microsoft.rest.v2.http.SharedChannelPool - 77156491   AVAIL   181s    182s    https://REDACTED.blob.core.windows.net:443
18:19:48.504 205727 [nioEventLoopGroup-1-2] INFO  com.microsoft.rest.v2.http.SharedChannelPool - 8afa7171   AVAIL   182s    182s    https://REDACTED.blob.core.windows.net:443

我仍然可以使用该应用程序并执行其他上载操作,但是我不确定是否必须清除任何未使用的连接。或者,如果我可以忽略这些错误。

编辑:添加了使用的代码示例

public class AzureCopy
{
    private final ContainerURL containerURL;

    public AzureCopy() throws InvalidKeyException, MalformedURLException
    {
        final String accountName = ConfHelper.getString("AZURE_ACCOUNT");
        final String accountKey = ConfHelper.getString("AZURE_KEY");

        final SharedKeyCredentials creds = new SharedKeyCredentials(accountName, accountKey);

        final ServiceURL serviceURL = new ServiceURL(new URL("https://" + accountName + ".blob.core.windows.net"), StorageURL.createPipeline(creds, new PipelineOptions()));

        containerURL = serviceURL.createContainerURL(ConfHelper.getString("AZURE_CONTAINER"));
    }

    public void upload(final File toUpload)
    {
        if(toUpload != null)
        {
            final BlockBlobURL blobURL = containerURL.createBlockBlobURL(toUpload.getName());

            try
            {
                uploadFile(blobURL, toUpload);
            }
            catch(final IOException e)
            {
                e.printStackTrace();
            }
        }
    }

    private static void uploadFile(final BlockBlobURL blob, final File sourceFile) throws IOException
    {
        final AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(sourceFile.toPath());

        TransferManager.uploadFileToBlockBlob(fileChannel, blob, 8 * 1024 * 1024, null, null).subscribe(response -> System.out.println("Completed upload request. : " + response.response().statusCode()));
    }
}

如您所见,这主要是示例代码,该代码可在github上获得,而没有交互式菜单。此类在应用程序的开头实例化,当我们需要上传文件时,将调用upload方法。而已。我们不会每次都创建一个新实例,而是在需要时重复使用同一实例。

0 个答案:

没有答案