Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Deadlock in RetryingConnectionImpl when tearing down a connection (
#406) * fix: Deadlock in RetryingConnectionImpl when tearing down a connection Also use a shared executor for all GRPC clients to reduce total threadcount and fix errors when tearing down executors used by GRPC connections. Also add logging to RetryingConnectionImpl Also ensure all calls out from RetryingConnectionImpl cannot leak exceptions. * fix: More fixes
- Loading branch information
1 parent
509dad6
commit af77486
Showing
3 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/Lazy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.pubsublite.internal; | ||
|
||
import java.util.function.Supplier; | ||
import javax.annotation.Nullable; | ||
import javax.annotation.concurrent.GuardedBy; | ||
|
||
/** A thread-safe, lazily constructed instance of an object. */ | ||
public class Lazy<T> { | ||
@GuardedBy("this") | ||
private @Nullable T instance = null; | ||
|
||
private final Supplier<T> supplier; | ||
|
||
public Lazy(Supplier<T> supplier) { | ||
this.supplier = supplier; | ||
} | ||
|
||
public synchronized T get() { | ||
if (instance == null) instance = supplier.get(); | ||
return instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters