Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal inconsistency: Could not find device with connection handle 0 #31

Open
rosek86 opened this issue Nov 21, 2016 · 4 comments
Open
Labels

Comments

@rosek86
Copy link

rosek86 commented Nov 21, 2016

Hi,

Sometimes when I try to connect to a particular device, the driver stucks in adapter.connect function. There is no connect callback and I don't get connectTimeOut event too.

After a while there is disconnect failed message:

"message": "Disconnect failed", "description": "Internal inconsistency: Could not find device with connection handle 0"

I tried to add additional timeout for connect method but next time I try to connect to a device this message appears:

Cannot connect message=Could not connect. Another connect is in progress., description=undefined

Do you have any suggestion how to fix this, please?

@bihanssen
Copy link
Contributor

Hi, it appears that a Connected event has gone missing. I base this on that you receive a Disconnected event. It's not clear however where the event has gotten lost. What you could do is turn the logLevel option in adapter.Open to debug and collect the info for investigation.

@rosek86
Copy link
Author

rosek86 commented Nov 22, 2016

Hi,

Please find attached application log, it contains all data from application start to "Disconnect failed" message. The "Status Connecting..." message indicate adapter.connect function.

application.txt

@rosek86
Copy link
Author

rosek86 commented Nov 22, 2016

Hi again,

Okay, I know what's wrong. My problem is in nan module layer,- there is a 64 slots queue for all events. I have around 15 peripheral devices around, sending advertisement and scan response packets. I'm testing this on Intel Edison which isn't able to get all these events in time before queue is full. That's why connection event is occasionally lost.

I've temporarily increased events queue to 512 slots and this works fine. Much better solution is to have one queue for advertisement/scan response events and second other events.

const auto EVENT_QUEUE_SIZE = 512;
(in adapter.h)

and to confirm I added queue full message in driver.cpp:

void Adapter::appendEvent(sd_rpc_evt_t *event)
{
(...)
    auto eventAdded = eventQueue.push(eventEntry);
    if (!eventAdded) {
      std::cerr << "Queue is full." << std::endl;
    }

"Queue is full" message appears occasionally when I have 64 slots.

Best regards

@bihanssen
Copy link
Contributor

Thanks for the update! Good catch finding the culprit, we should add a fix for it. Your suggestion about two queues sounds like a good solution.

@bihanssen bihanssen added the bug label Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants