Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.github.tobato.fastdfs.exception.FdfsConnectException: 无法获取服务端连接资源:can't create connection to/172.17.0.1:23000 #289

Open
xuanyuanbao opened this issue May 29, 2023 · 0 comments

Comments

@xuanyuanbao
Copy link

Exception in thread "myThreadPoolTaskExecutor-->1" java.lang.RuntimeException: com.github.tobato.fastdfs.exception.FdfsConnectException: 无法获取服务端连接资源:can't create connection to/172.17.0.1:23000
at tom.prizemanager.service.impl.ElasticsearchImageServiceImpl.getImageUrl(ElasticsearchImageServiceImpl.java:43)
at tom.prizemanager.service.impl.ArticleServiceImpl.updateOnES(ArticleServiceImpl.java:120)
at tom.prizemanager.service.impl.ArticleServiceImpl$$FastClassBySpringCGLIB$$1.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687)
at tom.prizemanager.service.impl.ArticleServiceImpl$$EnhancerBySpringCGLIB$$1.updateOnES()
at tom.prizemanager.job.SynchronousArticleInESJob.lambda$execute$0(SynchronousArticleInESJob.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.github.tobato.fastdfs.exception.FdfsConnectException: 无法获取服务端连接资源:can't create connection to/172.17.0.1:23000
at com.github.tobato.fastdfs.domain.conn.DefaultConnection.(DefaultConnection.java:56)
at com.github.tobato.fastdfs.domain.conn.PooledConnectionFactory.create(PooledConnectionFactory.java:56)
at com.github.tobato.fastdfs.domain.conn.PooledConnectionFactory.create(PooledConnectionFactory.java:22)
at org.apache.commons.pool2.BaseKeyedPooledObjectFactory.makeObject(BaseKeyedPooledObjectFactory.java:62)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.create(GenericKeyedObjectPool.java:1051)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:347)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:270)
at com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager.getConnection(FdfsConnectionManager.java:148)
at com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager.executeFdfsCmd(FdfsConnectionManager.java:63)
at com.github.tobato.fastdfs.service.DefaultFastFileStorageClient.uploadFileAndMetaData(DefaultFastFileStorageClient.java:223)
at com.github.tobato.fastdfs.service.DefaultFastFileStorageClient.uploadImage(DefaultFastFileStorageClient.java:145)
at tom.prizemanager.util.FastDFSUtil.uploadImage(FastDFSUtil.java:55)
at tom.prizemanager.service.impl.ElasticsearchImageServiceImpl.getImageUrl(ElasticsearchImageServiceImpl.java:41)
... 9 more
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:81)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:162)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)
at java.net.Socket.connect(Socket.java:606)
at com.github.tobato.fastdfs.domain.conn.DefaultConnection.(DefaultConnection.java:54)
... 21 more

46c24fa96fa3638f6b938999a5cfd36

image

    public String uploadImage(URL url, int retry) throws Exception {
        try (InputStream inputStream = url.openStream()) {
            String image = url.toString();
            if (image == null || image.isEmpty()) { // 空值检查
                return "";
            }

            // 获取文件名
            int slashIndex = image.lastIndexOf("/");
            String filename = (slashIndex != -1) ? image.substring(slashIndex + 1) : image;

            // 获取文件后缀名
            int dotIndex = filename.lastIndexOf(".");
            String extName = (dotIndex != -1) ? filename.substring(dotIndex + 1) : "";

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[4096];
            int bytesRead;
            int contentLength = 0;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
                contentLength += bytesRead;
            }

            FastImageFile fastImageFile = new FastImageFile(
                    new ByteArrayInputStream(outputStream.toByteArray()),
                    contentLength,
                    extName,
                    null
            );
            StorePath storePath = fastFileStorageClient.uploadImage(fastImageFile);

            return "/file/" + storePath.getFullPath();
        } catch (FdfsIOException e) {
            if (retry-- > 0) {
//                Thread.sleep(500);
                return uploadImage(url, retry);
            } else {
                log.error("uploadImage fail, url={}", url.toString());
                return null;
            }
        }
    }

想请问一下,这个是什么问题啊,我在服务器容器里面可以上传图片,并且访问,但是一到程序配置连接就会出现这样子的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant