You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2021/07/07 09:33:37 UTC
[GitHub] [incubator-shenyu] verysimple44 opened a new issue #1730: ReadTimeoutHandler on a channel which in a PooledConnectionProvider would cause an unexpected ReadTimeoutException
verysimple44 opened a new issue #1730:
URL: https://github.com/apache/incubator-shenyu/issues/1730
## Describe the bug
In brief, might we shouldn't use ReadTimeoutHandler when channel is reusable. For example, a business server spends 2s for processing each request, and I add a ReadTimeoutHandler(5s), it will still cause a TimeoutException in some case.
A scheduling ReaderIdleTimeoutTask will be submit when channel is active, but it won't be canceled when channel is returned to the pool, it won't recount when channel was used again either.
If the channel is used by next request, and a ReadTimeoutException might be thrown by the scheduling ReaderIdleTimeoutTask while the request was sent to a business server but not returned yet, the front side(may be an app, browser or postman) will receive an error with "{code: 500, message: internal error...}", but the business server always returns to gateway quickly.
## Environment
- ShenYu version(s): 2.3.0(release)
## Steps to reproduce
It occur in the prod environment, and there is the way reproduce it in local environment.
1. Make the configration like this.
```yml
soul:
httpclient:
readTimeout: 5000
writeTimeout: 5000
pool:
type:
ELASTIC
```
2. Create an http endpoint to mock business server with sleeping for 2s, the error will be reproduce easily.
```java
@GetMapping("/findByUserId")
public UserDTO findByUserId(@RequestParam("userId") final String userId) throws InterruptedException {
UserDTO userDTO = new UserDTO();
userDTO.setUserId(userId);
userDTO.setUserName("hello world");
Thread.sleep(2000L);
return userDTO;
}
```
3. Use a ip address to access the gateway and http endpoint but not a domain, it will be reproduce easily.
4. Processing request once, then processing the second request after 4s.
## Expected behavior
## Debug logs

</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shenyu] verysimple44 commented on issue #1730: ReadTimeoutHandler on a channel which in a PooledConnectionProvider would cause an unexpected ReadTimeoutException
Posted by GitBox <gi...@apache.org>.
verysimple44 commented on issue #1730:
URL: https://github.com/apache/incubator-shenyu/issues/1730#issuecomment-875485686
master, in org.apache.shenyu.springboot.starter.plugin.httpclient.HttpClientPluginConfiguration#httpClient
you add a ReadTimeoutHandler also, fix it by other way?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shenyu] yu199195 commented on issue #1730: ReadTimeoutHandler on a channel which in a PooledConnectionProvider would cause an unexpected ReadTimeoutException
Posted by GitBox <gi...@apache.org>.
yu199195 commented on issue #1730:
URL: https://github.com/apache/incubator-shenyu/issues/1730#issuecomment-875482225
in master,already fix it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shenyu] verysimple44 commented on issue #1730: ReadTimeoutHandler on a channel which in a PooledConnectionProvider would cause an unexpected ReadTimeoutException
Posted by GitBox <gi...@apache.org>.
verysimple44 commented on issue #1730:
URL: https://github.com/apache/incubator-shenyu/issues/1730#issuecomment-875462314
```java
// in io.netty.handler.timeout.IdleStateHandler
// By view IdleStateHandler, it might should not be used when channel is reusable
private final class ReaderIdleTimeoutTask extends AbstractIdleTask {
ReaderIdleTimeoutTask(ChannelHandlerContext ctx) {
super(ctx);
}
@Override
protected void run(ChannelHandlerContext ctx) {
long nextDelay = readerIdleTimeNanos;
// If the second request was sent to the business server, but the business server do not response yet, there is not on a reading state.
// First time nextDelay=3, Second time nextDelay<=0
if (!reading) {
nextDelay -= ticksInNanos() - lastReadTime;
}
if (nextDelay <= 0) {
readerIdleTimeout = schedule(ctx, this, readerIdleTimeNanos, TimeUnit.NANOSECONDS);
boolean first = firstReaderIdleEvent;
firstReaderIdleEvent = false;
try {
IdleStateEvent event = newIdleStateEvent(IdleState.READER_IDLE, first);
// call ReadTimeoutHandler#channelIdle, channel would be closed.
channelIdle(ctx, event);
} catch (Throwable t) {
ctx.fireExceptionCaught(t);
}
} else {
readerIdleTimeout = schedule(ctx, this, nextDelay, TimeUnit.NANOSECONDS);
}
}
}
```
```java
public class ReadTimeoutHandler extends IdleStateHandler {
private boolean closed;
public ReadTimeoutHandler(int timeoutSeconds) {
this(timeoutSeconds, TimeUnit.SECONDS);
}
public ReadTimeoutHandler(long timeout, TimeUnit unit) {
super(timeout, 0, 0, unit);
}
// it's going to close the channel
@Override
protected final void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {
assert evt.state() == IdleState.READER_IDLE;
readTimedOut(ctx);
}
protected void readTimedOut(ChannelHandlerContext ctx) throws Exception {
if (!closed) {
ctx.fireExceptionCaught(ReadTimeoutException.INSTANCE);
ctx.close();
closed = true;
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shenyu] verysimple44 commented on issue #1730: ReadTimeoutHandler on a channel which in a PooledConnectionProvider would cause an unexpected ReadTimeoutException
Posted by GitBox <gi...@apache.org>.
verysimple44 commented on issue #1730:
URL: https://github.com/apache/incubator-shenyu/issues/1730#issuecomment-876965455
I saw it at 1477ec983b115ddf2844a95d4fe9286407aa4758, so close it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-shenyu] verysimple44 closed issue #1730: ReadTimeoutHandler on a channel which in a PooledConnectionProvider would cause an unexpected ReadTimeoutException
Posted by GitBox <gi...@apache.org>.
verysimple44 closed issue #1730:
URL: https://github.com/apache/incubator-shenyu/issues/1730
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org