Comments (9)
@violetagg Thanks for the reply. I'll try to update the code as suggested by you.
from reactor-netty.
@Akshay-Sundarraj You should always defer the creation of the buffers. Something like this:
static Mono<String> execute(HttpClient httpClient, String uri) {
return Mono.defer(() -> {
return Mono.defer(() -> {
return httpClient.request(HttpMethod.POST)
.uri(uri)
.send((httpClientRequest, nettyOutbound) -> {
return nettyOutbound.send(Mono.create(sink -> {
ByteBuf buffer = ByteBufAllocator.DEFAULT.directBuffer();
buffer.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
sink.success(buffer);
}));
}).responseSingle(((response, byteBufMono) -> {
return byteBufMono.asString();
}));
}).doFinally(signalType -> {
});
});
}
from reactor-netty.
@violetagg Thanks for the suggestion. The thing is I need to fill the buffer with some binary values based on some binary protocol somewhere else and filling the buffer(serialising some objects) may throw errors. Basically buffer is created and filled in some other part. Is there any way I can handle this?
from reactor-netty.
@Akshay-Sundarraj I cannot help with creating the reactive pipeline as I do not know your project.
from reactor-netty.
@violetagg My question is reactor netty release buffer in some cases and does not release is some other cases. How can I know in what scenarios it doesn't relases?
from reactor-netty.
@Akshay-Sundarraj If we receive the buffer we will definitely release it, however here the HttpClient doesn't start sending at all as it cannot obtain a connection from the pool. That said the buffer consumption is lazy, we will not obtain the buffer as a first step. As a first step we need a connection that will be used for sending the request. Because of that you have to create the buffer only if there is a subscriber that will consume it, while now you create the buffer always regardless whether there is a subscriber or not.
from reactor-netty.
@violetagg I followed your suggestion of creating ByteBuf only when channel is acquired. i.e. inside send(). But now I'm getting different LEAK. Now I added TImeout to Http response Mono and resulting in ByteBuf leaks.
Minimal steps to reproduce the issue is available here https://gist.github.com/Akshay-Sundarraj/5bae74c268835ded6f128016c525cc2b
echoclient.log
I'm also uploading the collected logs to this message.
from reactor-netty.
@Akshay-Sundarraj The client should look like this:
static Mono<String> execute(HttpClient httpClient, String uri) {
return httpClient.post().uri(uri).send(((httpClientRequest,
nettyOutbound) -> {
int request = requestId.getAndIncrement();
httpClient.headers(headers -> headers.set("id", 1));
return nettyOutbound.send(
Mono.fromCallable(() -> {
ByteBuf buf = nettyOutbound.alloc().directBuffer()
.writeBytes(("Hello World " + Integer.toString(request)) .getBytes(StandardCharsets.UTF_8));
logger.fine("ByteBuffer refCount for request " + request +
" is " + buf.refCnt());
return buf;
})
.doOnNext(buf1 -> logger.fine("buffer is emitted for request " + request))
).then();
})).responseSingle(((response, byteBufMono) -> byteBufMono.asString())).
doFinally(signalType -> logger.fine("Http Mono is " +
"completed with " + signalType));
}
from reactor-netty.
@violetagg Thanks. This fixed the issue.
from reactor-netty.
Related Issues (20)
- Wiremock proxy : Connection prematurely closed BEFORE response HOT 2
- Add ability to set idle-timeout for websockets HOT 3
- Micrometer Prometheus metrics export fails due to conditional `proxy.address` tag HOT 2
- Intermittent error with connection reset by peer. HOT 3
- recordServerConnectionInactive never invoked after WebSocket upgrade HOT 1
- Metrics not disposed for `GracefulShutdownInstrumentedPool` HOT 1
- non-blocking call delayed accasionally. HOT 2
- Webclient timeout with Httpclient HOT 10
- Support SocketAddress for proxies HOT 2
- Support for changing the default compression level when enabling server response compression HOT 3
- Added configuration to disable dns using TransportConnector HOT 5
- The premature closure of a TCP connection, resulting in the error "Connection prematurely closed BEFORE response," affects another connection. HOT 3
- Need proper documentation for Default ConnectionPool and LoopResource usage with different hosts and/or port HOT 1
- Webclient active connection is struck - Direct buffer memory increase HOT 16
- MonoSend MAX_SIZE and REFILL_SIZE are not configurable HOT 6
- Netty does not provide errorLog just accesLog HOT 1
- http3 Error: connect ECONNREFUSED HOT 3
- Connection prematurely closed BEFORE response Internal timeout HOT 2
- HttpClient.reactorNettyVersion() throws NullPointException when loaded through -javaagent, under jdk 1.8
- The connection observed an error reactor.netty.channel.AbortedException: Connection has been closed HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactor-netty.