Code review comment: Thread-safe to mutate shared request config builder?

Code before review:
public void dispatch(HttpRequest wrapped, CompletableFuture<HttpResponse> vessel) {
Endpoint leastBusy = endpoints.get(0);
int min = Integer.MAX_VALUE;
int start = ++someNumber % endpoints.size();
for (int i = 0; i < endpoints.size(); i++) {
Endpoint endpoint = endpoints.get((i + start) % endpoints.size());
int inflight = endpoint.inflight.get();
if (inflight < min) {
leastBusy = endpoint;
min = inflight;
}
}
Endpoint endpoint = leastBusy;
endpoint.inflight.incrementAndGet();
dispatchExecutor.execute(() -> {
try {
SimpleHttpRequest request = new SimpleHttpRequest(wrapped.method(), wrapped.path());
request.setScheme(endpoint.url.getScheme());
request.setAuthority(new URIAuthority(endpoint.url.getHost(), portOf(endpoint.url)));
long timeoutMillis = wrapped.timeout() == null ? 190_000 : wrapped.timeout().toMillis() * 11 / 10 + 1_000;
request.setConfig(requestConfig.setResponseTimeout(Timeout.ofMilliseconds(timeoutMillis)).build());
defaultHeaders.forEach(request::setHeader);
wrapped.headers().forEach((name, value) -> request.setHeader(name, value.get()));
if (wrapped.body() != null) {
byte[] body = wrapped.body();
if (compression == gzip || compression == auto && body.length > 512) {
request.setHeader(gzipEncodingHeader);
body = gzipped(body);
}
request.setBody(body, ContentType.APPLICATION_JSON);
}
Future<?> future = endpoint.client.execute(request,
new FutureCallback<SimpleHttpResponse>() {
@Override public void completed(SimpleHttpResponse response) { vessel.complete(new ApacheHttpResponse(response)); }
@Override public void failed(Exception ex) { vessel.completeExceptionally(ex); }
@Override public void cancelled() { vessel.cancel(false); }
});
Future<?> cancellation = timeoutExecutor.schedule(() -> {
future.cancel(true);
vessel.cancel(true);
}, timeoutMillis + 10_000, TimeUnit.MILLISECONDS);
vessel.whenComplete((__, ___) -> cancellation.cancel(true));
}
catch (Throwable thrown) {
vessel.completeExceptionally(thrown);
}
vessel.whenComplete((__, ___) -> endpoint.inflight.decrementAndGet());
});
}

Line under review: request.setConfig(requestConfig.setResponseTimeout(Timeout.ofMilliseconds(timeoutMillis)).build());

Code after addressing the review:
public void dispatch(HttpRequest wrapped, CompletableFuture<HttpResponse> vessel) {
Endpoint leastBusy = endpoints.get(0);
int min = Integer.MAX_VALUE;
int start = ++someNumber % endpoints.size();
for (int i = 0; i < endpoints.size(); i++) {
Endpoint endpoint = endpoints.get((i + start) % endpoints.size());
int inflight = endpoint.inflight.get();
if (inflight < min) {
leastBusy = endpoint;
min = inflight;
}
}
Endpoint endpoint = leastBusy;
endpoint.inflight.incrementAndGet();
dispatchExecutor.execute(() -> {
try {
SimpleHttpRequest request = new SimpleHttpRequest(wrapped.method(), wrapped.path());
request.setScheme(endpoint.url.getScheme());
request.setAuthority(new URIAuthority(endpoint.url.getHost(), portOf(endpoint.url)));
long timeoutMillis = wrapped.timeout() == null ? 190_000 : wrapped.timeout().toMillis() * 11 / 10 + 1_000;
request.setConfig(RequestConfig.copy(requestConfig).setResponseTimeout(Timeout.ofMilliseconds(timeoutMillis)).build());
defaultHeaders.forEach(request::setHeader);
wrapped.headers().forEach((name, value) -> request.setHeader(name, value.get()));
if (wrapped.body() != null) {
byte[] body = wrapped.body();
if (compression == gzip || compression == auto && body.length > 512) {
request.setHeader(gzipEncodingHeader);
body = gzipped(body);
}
request.setBody(body, ContentType.APPLICATION_JSON);
}
Future<?> future = endpoint.client.execute(request,
new FutureCallback<SimpleHttpResponse>() {
@Override public void completed(SimpleHttpResponse response) { vessel.complete(new ApacheHttpResponse(response)); }
@Override public void failed(Exception ex) { vessel.completeExceptionally(ex); }
@Override public void cancelled() { vessel.cancel(false); }
});
Future<?> cancellation = timeoutExecutor.schedule(() -> { future.cancel(true); vessel.cancel(true); },
timeoutMillis + 10_000,
TimeUnit.MILLISECONDS);
vessel.whenComplete((__, ___) -> cancellation.cancel(true));
}
catch (Throwable thrown) {
vessel.completeExceptionally(thrown);
}
vessel.whenComplete((__, ___) -> endpoint.inflight.decrementAndGet());
});
}