开发者社区> 问答> 正文

偶发性的Caused bycom.aliyun.oss.ClientExceptionConnectionTimeout

问题是偶发的,有的无从下手的感觉,感觉是网络问题。但OSS和ECS都是一个中心的。不知道如何优化了。求大神指点。


Caused by: com.aliyun.oss.ClientException: ConnectionTimeout
at com.aliyun.oss.common.utils.ExceptionFactory.createNetworkException(ExceptionFactory.java:68)
at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:67)
at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:121)
at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:67)
at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:89)
at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:130)
at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:108)
at com.aliyun.oss.internal.OSSObjectOperation.writeObjectInternal(OSSObjectOperation.java:574)
at com.aliyun.oss.internal.OSSObjectOperation.putObject(OSSObjectOperation.java:119)
at com.aliyun.oss.OSSClient.putObject(OSSClient.java:412)
at com.aliyun.oss.OSSClient.putObject(OSSClient.java:399)
at cn.***.framework.web.AbstractOSSFileUploadService.upload(AbstractOSSFileUploadService.java:321)
at cn.***.framework.web.AbstractOSSFileUploadService.upload(AbstractOSSFileUploadService.java:494)
at com.***.doctor.service.DoctorImage.uploadHeadIcon(DoctorImage.java:178)
... 36 more
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to ***.oss-cn-beijing.aliyuncs.com:80 timed out
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
at org.apache.http.impl.client.Closeable(和谐)HttpClient.execute(Closeable(和谐)HttpClient.java:82)
at org.apache.http.impl.client.Closeable(和谐)HttpClient.execute(Closeable(和谐)HttpClient.java:107)
at org.apache.http.impl.client.Closeable(和谐)HttpClient.execute(Closeable(和谐)HttpClient.java:55)
at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:64)
... 48 more
涉及公司的关键词统一用***代替了
上传用的代码。
protected SystemUploadFile upload(String fileName) {
        SystemUploadFile suf;
        try {
            //获取表单文件字段的数据
            Part part = ThreadLocalParameter.getThreadLocal().getRequest().getPart(formField);
            if (part == null) {
                return null;
            }
            //获取提交文件的名称
            String uploadFileName = part.getSubmittedFileName();
            if (uploadFileName == null || uploadFileName.isEmpty()) {
                return null;
            }
            if (fileName.indexOf("/") == 0) {
                fileName = fileName.replaceFirst("/", "");
            }

            if (uploadFileName.contains(".")) {
                fileName += uploadFileName.substring(uploadFileName.lastIndexOf("."));
            }
            //拼接prefix
            String filePath = oss_prefix + "/" + fileName;
            InputStream in;
            in = null;

            try {

                in = part.getInputStream();
                // 创建上传Object的Metadata
                ObjectMetadata meta = new ObjectMetadata();
                // 必须设置ContentLength
                meta.setContentLength(part.getSize());
//                if(client==null){
//                    client = new OSSClient(oss_endpoint, access_id, access_key);
//                }
                // 上传Object.
                PutObjectResult result = getClient().putObject(bucket, filePath, in, meta);
            } catch (IOException ex) {
                Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "上传文件失败", ex);
                return null;
            } finally {
                if (in != null) {
                    in.close();
                }
            }
            suf = new SystemUploadFile();
            suf.setFilePath(fileName);
            suf.setFileSize(part.getSize());
            suf.setFileType(part.getContentType());
            suf.setUploadTimeStamp(new Date());
        } catch (IOException | ServletException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "上传文件失败", ex);
            return null;
        }
        return suf;
    }





展开
收起
qq马家大少 2015-12-06 10:33:39 13161 0
4 条回答
写回答
取消 提交回答
  • 从错误来看,connection timeout很可能是因为本地连接过多,导致端口被占用过多,无法再连接新的请求。
    现象:
    看本地网络连接的状态,TIME_WAIT状态很多,并且不能重用。
    解决方法:
    可以搜下TIME_WAIT过多,看看其他人是如何解决的
    2016-06-28 10:18:51
    赞同 展开评论 打赏
  • Re偶发性的Caused bycom.aliyun.oss.ClientExceptionConnectionTimeout
    我们在国外节点也遇到这个问题,可以ping通,程序在运行一段时间后,就会偶发性的出现这个问题。

    -------------------------

    Re偶发性的Caused bycom.aliyun.oss.ClientExceptionConnectionTimeout
    不知道,你们这个问题,最终是怎么解决的?
    2016-06-27 15:01:38
    赞同 展开评论 打赏
  • Re回 1楼西秦的帖子
    ping也没问题。就是连接超时。我再看看吧。
    ping ***.oss-cn-beijing.aliyuncs.com
    PING oss-cn-beijing.aliyuncs.com (182.92.18.4) 56(84) bytes of data.
    64 bytes from 182.92.18.4: icmp_seq=1 ttl=60 time=0.178 ms
    64 bytes from 182.92.18.4: icmp_seq=2 ttl=60 time=0.189 ms
    64 bytes from 182.92.18.4: icmp_seq=3 ttl=60 time=0.168 ms
    64 bytes from 182.92.18.4: icmp_seq=4 ttl=60 time=0.197 ms
    64 bytes from 182.92.18.4: icmp_seq=5 ttl=60 time=0.169 ms
    64 bytes from 182.92.18.4: icmp_seq=6 ttl=60 time=0.166 ms
    64 bytes from 182.92.18.4: icmp_seq=7 ttl=60 time=0.160 ms
    64 bytes from 182.92.18.4: icmp_seq=8 ttl=60 time=0.167 ms
    64 bytes from 182.92.18.4: icmp_seq=9 ttl=60 time=0.173 ms
    64 bytes from 182.92.18.4: icmp_seq=10 ttl=60 time=0.218 ms
    64 bytes from 182.92.18.4: icmp_seq=11 ttl=60 time=0.179 ms
    64 bytes from 182.92.18.4: icmp_seq=12 ttl=60 time=0.196 ms
    64 bytes from 182.92.18.4: icmp_seq=13 ttl=60 time=0.169 ms
    64 bytes from 182.92.18.4: icmp_seq=14 ttl=60 time=0.168 ms
    64 bytes from 182.92.18.4: icmp_seq=15 ttl=60 time=0.184 ms
    64 bytes from 182.92.18.4: icmp_seq=16 ttl=60 time=0.193 ms
    64 bytes from 182.92.18.4: icmp_seq=17 ttl=60 time=0.221 ms
    64 bytes from 182.92.18.4: icmp_seq=18 ttl=60 time=0.187 ms
    64 bytes from 182.92.18.4: icmp_seq=19 ttl=60 time=0.170 ms
    64 bytes from 182.92.18.4: icmp_seq=20 ttl=60 time=0.189 ms
    64 bytes from 182.92.18.4: icmp_seq=21 ttl=60 time=0.187 ms
    64 bytes from 182.92.18.4: icmp_seq=22 ttl=60 time=0.182 ms
    64 bytes from 182.92.18.4: icmp_seq=23 ttl=60 time=0.198 ms


    2015-12-06 12:24:12
    赞同 展开评论 打赏
  • 码农|Coder| Pythonista
    建议您更换地理距离更近的节点,或者修改SDK的超时验证时间
    2015-12-06 10:42:22
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载