project-mirai / mirai-api-http

Mirai HTTP API (console) plugin
GNU Affero General Public License v3.0
1.66k stars 343 forks source link

webhook 指定的目标服务多次返回500后,即使目标服务恢复,回调也无法正常工作 #622

Closed Bpazy closed 2 years ago

Bpazy commented 2 years ago

mirai 版本: 2.12.1 各插件版本:

net.mamoe:mirai-console v2.12.1
net.mamoe:mirai-console-terminal v2.12.1
net.mamoe:mirai-core-all v2.12.1
org.itxtech:mcl-addon v2.0.2
org.bouncycastle:bcprov-jdk15on v1.64
net.mamoe:mirai-api-http v2.6.1

setting.yml:

adapters: 
  - http
  - webhook
debug: true
enableVerify: true
verifyKey: 1234567890
singleMode: false
cacheSize: 4096
persistenceFactory: 'built-in'
adapterSettings: 
  webhook:
    ## 回调(上报)地址
    destinations: 
    - 'localhost:10000/post'

异常堆栈:

2022-09-08 17:15:30 V/Bot.1965842929: [test(1044740132)] Bpazy(51*****80) -> 1
2022-09-08 17:15:40 E/Mah Debug: io.ktor.network.sockets.SocketTimeoutException: Socket timeout has expired [url=http://localhost:10000/post, socket_timeout=unknown] ms
io.ktor.network.sockets.SocketTimeoutException: Socket timeout has expired [url=http://localhost:10000/post, socket_timeout=unknown] ms
        at mirai-api-http-2.6.1.jar[shared]//io.ktor.client.features.HttpTimeoutKt.SocketTimeoutException(HttpTimeout.kt:207)
        at mirai-api-http-2.6.1.jar[shared]//io.ktor.client.engine.okhttp.OkUtilsKt.mapOkHttpException(OkUtils.kt:79)
        at mirai-api-http-2.6.1.jar[shared]//io.ktor.client.engine.okhttp.OkUtilsKt.access$mapOkHttpException(OkUtils.kt:1)
        at mirai-api-http-2.6.1.jar[shared]//io.ktor.client.engine.okhttp.OkHttpCallback.onFailure(OkUtils.kt:39)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:525)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.net.SocketTimeoutException: timeout
        at mirai-api-http-2.6.1.jar[shared]//okio.SocketAsyncTimeout.newTimeoutException(JvmOkio.kt:143)
        at mirai-api-http-2.6.1.jar[shared]//okio.AsyncTimeout.access$newTimeoutException(AsyncTimeout.kt:162)
        at mirai-api-http-2.6.1.jar[shared]//okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:335)
        at mirai-api-http-2.6.1.jar[shared]//okio.RealBufferedSource.indexOf(RealBufferedSource.kt:427)
        at mirai-api-http-2.6.1.jar[shared]//okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:320)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:178)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:106)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:79)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
        at mirai-api-http-2.6.1.jar[shared]//okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
        ... 3 more
Caused by: java.net.SocketException: Socket closed
        at java.base/sun.nio.ch.NioSocketImpl.endRead(NioSocketImpl.java:248)
        at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:327)
        at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:350)
        at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:803)
        at java.base/java.net.Socket$SocketInputStream.read(Socket.java:966)
        at mirai-api-http-2.6.1.jar[shared]//okio.InputStreamSource.read(JvmOkio.kt:90)
        at mirai-api-http-2.6.1.jar[shared]//okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:129)
        ... 20 more

目标服务可访问:

PS C:\Users\hanzi> curl http://localhost:10000/post

StatusCode        : 200
StatusDescription : OK
Content           : null
RawContent        : HTTP/1.1 200 OK
                    Content-Length: 4
                    Content-Type: application/json; charset=utf-8
                    Date: Thu, 08 Sep 2022 09:17:42 GMT

                    null
Forms             : {}
Headers           : {[Content-Length, 4], [Content-Type, application/json; charset=utf-8], [Date, Thu, 08 Sep 2022 09:1
                    7:42 GMT]}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 4
Bpazy commented 2 years ago

搞明白了。

我的服务通过 0.0.0.0:10000 启动,通过 localhost:10000 可访问,但是当换成 127.0.0.1:10000 时就不可访问了。尝试将服务绑定在 127.0.0.1:10000 发现端口被占用,进而发现端口被名为 SangforPromoteService 的服务占用