我的一个onError处理程序偶尔没有被调用,导致我的应用程序处于一种挥之不去的状态。
这是我的代码
tokenSubscription = Observable.interval(pluginProperties.getRefreshTokenInterval(), TimeUnit.MILLISECONDS, Schedulers.io())
.subscribe(x -> {
ConversationContextV3 contextV3 = (ConversationContextV3) authenticationContext.getConversationContext();
refreshAccessToken(contextV3);
},
error -> {
logger.error("Exception after retrying refreshing session token, will attempt to reconnect");
disconnect();
}
);
当调用refreshAccessToken()时,它有时会引发异常,然后在onError中处理。以下是预期产量。注意最后一行。
2017-09-04 20:11:27.750 [RxCachedThreadScheduler-82] DEBUG c.danlind.igz.brokerapi.BrokerLogin - Refreshing access token
2017-09-04 20:11:27.798 [RxCachedThreadScheduler-82] ERROR c.danlind.igz.adapter.RestApiAdapter - Exception when refreshing session token
org.springframework.web.client.HttpServerErrorException: 503 Service Unavailable
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:94)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531)
at com.danlind.igz.ig.api.client.RestAPI.refreshSessionV1(RestAPI.java:778)
at com.danlind.igz.adapter.RestApiAdapter.refreshSessionV1(RestApiAdapter.java:281)
at com.danlind.igz.brokerapi.BrokerLogin.refreshAccessToken(BrokerLogin.java:80)
at com.danlind.igz.brokerapi.BrokerLogin.lambda$startRefreshAccessTokenScheduler$17(BrokerLogin.java:99)
... (removed some lines for brevity)
2017-09-04 20:11:27.811 [RxCachedThreadScheduler-82] ERROR c.danlind.igz.brokerapi.BrokerLogin - Exception after retrying refreshing session token, disconnecting
2017-09-04 20:11:27.811 [RxCachedThreadScheduler-82] INFO c.danlind.igz.brokerapi.BrokerLogin - Disconnecting from IG
我的问题是,有时似乎从未调用过onError,让我得到这样的日志输出:
2017-09-04 20:11:27.750 [RxCachedThreadScheduler-82] DEBUG c.danlind.igz.brokerapi.BrokerLogin - Refreshing access token
2017-09-04 20:11:27.798 [RxCachedThreadScheduler-82] ERROR c.danlind.igz.adapter.RestApiAdapter - Exception when refreshing session token
org.springframework.web.client.HttpServerErrorException: 503 Service Unavailable
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:94)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531)
at com.danlind.igz.ig.api.client.RestAPI.refreshSessionV1(RestAPI.java:778)
at com.danlind.igz.adapter.RestApiAdapter.refreshSessionV1(RestApiAdapter.java:281)
at com.danlind.igz.brokerapi.BrokerLogin.refreshAccessToken(BrokerLogin.java:80)
at com.danlind.igz.brokerapi.BrokerLogin.lambda$startRefreshAccessTokenScheduler$17(BrokerLogin.java:99)
... (removed some lines for brevity)
我的代码感觉非常直接,我无法理解会导致这个"故障的问题"?有任何想法吗?使用RxJava 2.10