somakeit / door-controller2

A new door controller for a new space, where all the previous hardware is broken and we can't replace it.
1 stars 0 forks source link

Repeated crash of child process when network disconnects after init. #16

Closed brackendawson closed 8 years ago

brackendawson commented 8 years ago
Feb 15 07:42:20 kong doord: Process Process-4527:
Feb 15 07:42:20 kong doord: Traceback (most recent call last):
Feb 15 07:42:20 kong doord:   File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
Feb 15 07:42:20 kong doord:     self.run()
Feb 15 07:42:20 kong doord:   File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
Feb 15 07:42:20 kong doord:     self._target(*self._args, **self._kwargs)
Feb 15 07:42:20 kong doord:   File "/home/bracken/door-controller2/doord.py", line 746, in _server_poll_worker
Feb 15 07:42:20 kong doord:     print "GET request error: " + str(e) + " - " + str(response.text)
Feb 15 07:42:20 kong doord: UnboundLocalError: local variable 'response' referenced before assignment
benjie commented 8 years ago

That's if an exception is thrown before the the response variable can be set.

Whilst scanning through I also noticed this:

https://github.com/somakeit/door-controller2/blob/4e77489cc3a6f8b96f5831d6c1649ab2831c4929/doord.py#L700-L703

            for i in range(len(self.send_queue)):
                response = requests.post(self.server_url,
                                         cookies={'SECRET': self.api_key},
                                         data = json.dumps(self.send_queue[i]),
                                         headers={'content-type': 'application/json'})
            if response.status_code == requests.codes.ok:
                self.send_queue.pop(i)
            else:
                raise EntryDatabaseException("Server returned bad status to POST:" + str(response.status_code) + " - " + str(response.text)) + " (send_queue: " + str(len(self.send_queue)) + ")"

I think the if block should also be indented inside the for loop?

brackendawson commented 8 years ago

I need to have a very close look at the send queue before I can agree there, but I expect you're right and I'd have commented if it should be outside the loop.

WRT the exception, will close this issue after reviewing all except blocks for the same. I know what it was the moment I saw the stacktrace.

brackendawson commented 8 years ago

On the plus side: I noticed this when a tag init'd but failed to appear in members area: The software did log the keys that locked the tag so I can erase it again. It did make it impossible for me to cheat and manually enter it in the members area by throwing away the secret. People's tag counts have fallen behind on the server but people can still get in and counts are now updating.

The disconnect seems to have been handled as designed.

The disconnect seems to have happened after a USB glitch on the Eth device that happens now and then. Afterwards the link came up but the dhcp client just wouldn't get a lease. I set kong to static IP now.

brackendawson commented 8 years ago

I'm writing unit tests and just spent 10 solid minutes debugging that indentation thing, that I knew I would also fix today.

Also a for loop is inappropriate due to the use of i and pop.

brackendawson commented 8 years ago

fixed by 464341e