kevinherron / ua-client-sdk

OPC-UA Client SDK for Java
27 stars 16 forks source link

Bad_NoSubscription fault on unsubscribe #5

Closed comtel2000 closed 8 years ago

comtel2000 commented 8 years ago

I get two fault messages (client.addFaultListener(fault -> ) with StatusCode{name=Bad_NoSubscription, value=0x80790000, quality=bad} after unsubscribe a variable with: client.getSubscriptionManager().deleteSubscription(subscriptionId); It seems that, deleteSubscription method is triggered the unsubscribe message 3 times.

kevinherron commented 8 years ago

Are you calling deleteSubscription() more than once?

comtel2000 commented 8 years ago

no, only once

kevinherron commented 8 years ago

Are you able to show me more of the surrounding code? Or perhaps obtain a Wireshark capture? I can only guess as to what is happening with more information, but I can see that I have not seen any issue like this so far.

comtel2000 commented 8 years ago

based on your sdk-examples I get 2 errors:

22:15:54.934 [ua-shared-pool-4] ERROR c.d.o.s.e.c.UnSubscriptionExample - fault on StatusCode{name=Bad_NoSubscription, value=0x80790000, quality=bad}
22:15:54.934 [ua-shared-pool-1] ERROR c.d.o.s.e.c.UnSubscriptionExample - fault on StatusCode{name=Bad_NoSubscription, value=0x80790000, quality=bad}
public class UnSubscriptionExample implements ClientExample {

    public static void main(String[] args) throws Exception {
        String endpointUrl = "opc.tcp://localhost:12685";

        UnSubscriptionExample example = new UnSubscriptionExample();

        new ClientExampleRunner(endpointUrl, example).run();
    }

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private final AtomicLong clientHandles = new AtomicLong(1L);

    @Override
    public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
        // synchronous connect
        client.connect().get();
        client.addFaultListener(fault -> logger.error("fault on {}", fault.getResponseHeader().getServiceResult()));
        // create a subscription and a monitored item
        UaSubscription subscription = client.getSubscriptionManager().createSubscription(1000.0).get();

        ReadValueId readValueId = new ReadValueId(
                Identifiers.Server_ServerStatus_CurrentTime,
                AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE);

        // client handle must be unique per item
        UInteger clientHandle = uint(clientHandles.getAndIncrement());

        MonitoringParameters parameters = new MonitoringParameters(
                clientHandle,
                1000.0,     // sampling interval
                null,       // filter, null means use default
                uint(10),   // queue size
                true);      // discard oldest

        MonitoredItemCreateRequest request = new MonitoredItemCreateRequest(
                readValueId, MonitoringMode.Reporting, parameters);

        List<UaMonitoredItem> items = subscription
                .createMonitoredItems(TimestampsToReturn.Both, newArrayList(request)).get();

        // do something with the value updates
        UaMonitoredItem item = items.get(0);

        item.setValueConsumer(v -> {
            logger.info("value received: {}", v.getValue());
        });

        client.getSubscriptionManager().deleteSubscription(subscription.getSubscriptionId()).whenComplete((a, b) -> {
            future.complete(client);
        });
    }

}
kevinherron commented 8 years ago

Ah, right. Okay. I know what's happening.

I'm not sure this is exactly a bug, but it's certainly misleading. Those service faults are the server returning service faults for two outstanding PublishRequests because there are no subscriptions, since you just deleted the only one. If they continued to be sent and failed even while there were no subscriptions I think it would be a bug, but if it's just the two outstanding requests that fail it's harmless.

kevinherron commented 8 years ago

@comtel2000 if the UA client you're writing ends up open source I would probably be interested in contributing. I've actually started writing my own JavaFX client as it is, but you seem to be farther along. One thing I've noticed in the process is that I made some poor decisions about the AddressSpace and Node api in the client SDK, which I hope to fix once this project moves to the Eclipse foundation and enters its incubation period.

comtel2000 commented 8 years ago

Kevin, yes it's open source but I struggling with the right licence. I would prever Apache L2 or BSD. Is it compatible with your AGPL? I need 1 or 2 days to cleanup the code after that I push it to github. Best regards, Joerg

kevinherron commented 8 years ago

As I mentioned, the project is moving to Eclipse Foundation, at which point it will be licensed under the EPL/EDL and will be compatible.

comtel2000 commented 8 years ago

That's great! Client UI is online: https://github.com/comtel2000/opc-ua-client