This is an automated email from the ASF dual-hosted git repository.

chenhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new d111476  Add a default timeout for OAuth2 Metadata Resolver (#14056)
d111476 is described below

commit d11147616aa6cc7888420f6325bb71cd7f7ab065
Author: Addison Higham <[email protected]>
AuthorDate: Sun Jan 30 00:51:44 2022 -0700

    Add a default timeout for OAuth2 Metadata Resolver (#14056)
    
    ## Motivation
    Currently, there is no timeout on the metadata resolver in oauth2
    clients.
    
    This can result in a connection hanging indefintely.
    
    We should add sane defaults here.
    
    ## Modification
    These defaults match the defaults of the TokenClient and generally the
    Pulsar defaults of 10s connect timeout and 30s read timeout
    
    ## Test
    
    This seems to primarily depend on testing timeout of the java HTTP lib, so 
no test is likely needed.
    
    ## Doc
    
    This is a trivial change and doesn't require docs
---
 .../client/impl/auth/oauth2/protocol/DefaultMetadataResolver.java   | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git 
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/protocol/DefaultMetadataResolver.java
 
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/protocol/DefaultMetadataResolver.java
index 2c09113..7d6ca1e 100644
--- 
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/protocol/DefaultMetadataResolver.java
+++ 
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/protocol/DefaultMetadataResolver.java
@@ -33,6 +33,9 @@ import java.time.Duration;
  */
 public class DefaultMetadataResolver implements MetadataResolver {
 
+    protected static final int DEFAULT_CONNECT_TIMEOUT_IN_SECONDS = 10;
+    protected static final int DEFAULT_READ_TIMEOUT_IN_SECONDS = 30;
+
     private final URL metadataUrl;
     private final ObjectReader objectReader;
     private Duration connectTimeout;
@@ -41,6 +44,9 @@ public class DefaultMetadataResolver implements 
MetadataResolver {
     public DefaultMetadataResolver(URL metadataUrl) {
         this.metadataUrl = metadataUrl;
         this.objectReader = new ObjectMapper().readerFor(Metadata.class);
+        // set a default timeout to ensure that this doesn't block
+        this.connectTimeout = 
Duration.ofSeconds(DEFAULT_CONNECT_TIMEOUT_IN_SECONDS);
+        this.readTimeout = Duration.ofSeconds(DEFAULT_READ_TIMEOUT_IN_SECONDS);
     }
 
     public DefaultMetadataResolver withConnectTimeout(Duration connectTimeout) 
{

Reply via email to