Skip to content

Commit

Permalink
Merge #3582 into 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Jan 7, 2025
2 parents 40a880e + c29b0fe commit 5889434
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2024 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2021-2025 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -339,6 +339,11 @@ else if (testEvictionPredicate(ref.slot)) {
}

void doAcquire(Borrower borrower) {
if (borrower.get()) {
// Borrower is cancelled, do nothing
return;
}

if (isDisposed()) {
borrower.fail(new PoolShutdownException());
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2024 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2021-2025 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@
import io.netty.handler.codec.http2.Http2FrameCodecBuilder;
import io.netty.handler.codec.http2.Http2MultiplexHandler;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Subscription;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand All @@ -46,6 +47,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -141,6 +143,28 @@ void acquireRelease() {
}
}

@Test
void doAcquireNotCalledIfBorrowerInScopeCancelledEarly() {
AtomicInteger allocator = new AtomicInteger();
PoolBuilder<Connection, PoolConfig<Connection>> poolBuilder =
PoolBuilder.from(Mono.fromSupplier(() -> {
allocator.incrementAndGet();
Channel channel = new EmbeddedChannel(
new TestChannelId(),
Http2FrameCodecBuilder.forClient().build());
return Connection.from(channel);
}));

Http2Pool http2Pool = poolBuilder.build(config -> new Http2Pool(config, null));

assertThat(allocator).as("before invoking acquire").hasValue(0);

// Borrower is in state cancelled before the actual acquisition
http2Pool.acquire().doOnSubscribe(Subscription::cancel).subscribe();

assertThat(allocator).as("after invoking acquire").hasValue(0);
}

@Test
void evictClosedConnection() throws Exception {
PoolBuilder<Connection, PoolConfig<Connection>> poolBuilder =
Expand Down

0 comments on commit 5889434

Please sign in to comment.