Azure / azure-relay-java

Azure Relay Java SDK
MIT License
8 stars 9 forks source link

HybridConnectionListener can't reconnect to hybridConnection by itself in case of short-time network connection failure #55

Closed piotrnk closed 4 years ago

piotrnk commented 4 years ago

1) HybridConnectionListener can't reconnect to hybridConnection by itself in case of network connection issue (I am disabling/enabling the ethernet on my pc for testing). In case listener went to offline status, it can't be opened again as there is an exception: IllegalStateException: Invalid operation: Invalid operation. Cannot call open when it's already closed.

2) In case of short network connection failure, when I programmed building a new HybridConnectionListener object, the result is the hybrid connection work back but WebSocketClient Threads are multiplicated

3) HybridConnectionListener offline handler is not triggered when a network connection breaks. Listener goes to 'offline' status, but handler is not triggered.

4) In case of connection string is renewed in Azure portal, I can't see any method/option to update connection string in TokenProvider, the only option is to build a new HybridConnectionListener. How this case should be handled? (see point 2 on opening a new listener object)

Connection failure can be reproduced with the sample provided in azure-relay repository: https://github.com/Azure/azure-relay/blob/master/samples/hybrid-connections/java/simple-websocket-demo/src/main/java/WebsocketListener.java

I also added a repository with a sample - which reconnects on failure, but multiplicates WebSocketClient threads: https://github.com/piotrnk/azure-relay-java-test-samples/blob/master/src/main/java/tester/WebsocketListener.java

dlstucki commented 4 years ago

On point 4 you could write a class extending TokenProvider that allows changing the key-name+key_value or a signature itself. Pseudo-code

public class UpdatableSharedAccessSignatureTokenProvider extends TokenProvider {

    // When the credentials change replace this object:  
    private /*SharedAccessSignature*/TokenProvider innerSasTokenProvider;

    . . . 

    public void updateCredentials(String keyName, String keyValue) {
        this.innerSasTokenProvider = TokenProvider.createSharedAccessSignatureTokenProvider(keyName, keyValue);
    }
    public void updateCredentials(String signature) {
        this.innerSasTokenProvider = TokenProvider.createSharedAccessSignatureTokenProvider(signature);
    }

    @Override
    protected CompletableFuture<SecurityToken> onGetTokenAsync(String resource, Duration validFor) {
        return this.innerSasTokenProvider.GetTokenAsync(resource, duration);
    }
piotrnk commented 4 years ago

Can I kindly ask if there is a chance the problems from point 1 and 2 will be addressed?

piotrnk commented 4 years ago

I see the issue fixed on 'dev' branch, Can i ask when this fix will be released?

jfggdl commented 4 years ago

@piotrnk Thanks for reporting this issue. We will release a fix on the next release which currently is planned to be completed by March/April.

dlstucki commented 4 years ago

It's now released: https://github.com/Azure/azure-relay-java/releases/tag/0.0.3