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

Debugger hang fix #7

Merged
merged 5 commits into from
May 12, 2020
Merged

Debugger hang fix #7

merged 5 commits into from
May 12, 2020

Conversation

joshuamitchener
Copy link
Collaborator

No description provided.

Copy link
Owner

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! let's just make use of that size header 🚀

def handle(self):
# self.request is the TCP socket connected to the client
while True:
data = self.request.recv(65000).strip()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using the size to recv the correct amount of bytes here. you'll want to read in the header which is delimited by { to } and use the value of size to recv the remaining message

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be a more clean way to use recv, but I just received 1 byte using a while loop to get the size string. This did allow me to remove the regular expressions from the python code, which makes it overall cleaner.

Comment on lines +63 to +68
while True:
header = b""
while True:
header += self.request.recv(1)
if header and chr(header[-1]) == '}':
break
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this method, let us be a little more defensive and add a condition that if header is 1000 characters and we still haven't seen the closing curly we should exit with with failure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you prefer the program exit? Should it throw an exception and log an error message?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, makes me realize we might have added a bit of a bug here with program exiting in general, the old client loop function used to break the websocket loop which implicitly would lead to an exit. My advice it to have one actual sys.exit() point in the program and to reach that point via exceptions.

So I think try: except:-ing around serve_forever is appropriate, with except blocks for KeyboardInterruption, ProgramExit and CommunicationError (or ParseError, you decide) (the last two being exceptions of your own making) and handle them appropriately (for example program exit isn't actually a bad thing, we just want consistent exit strategies)

You should log what you think is best so here's a note about levels:
Will only be seen if someone passed -l to dashmips:

  • debug - for a developer to get detailed insight on the internals of a program (like dump of network traffic)
  • info - verbose information, like entering certain blocks of code or calling functions, intended for someone debugging an issue in production
  • warning - not an error but something that should be corrected

Will always print:

  • critical or error - something unexpected occurred the program cannot continue, this is in the realm of socket port in use, or permission denied, things entirely unfixable by our program

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I committed the changes I made, it should now exit with a message on both normal completion and if the message is too long (> 1000). Let me know if you still want me to add an exit for KeyboardInterruption!

Comment on lines 73 to 74
print("{} wrote:".format(self.client_address[0]))
print(command)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets search and replace prints with log.info or log.debug, this prevents clutter on the terminal when someone runs dashmips without the -l flag

Comment on lines +63 to +68
while True:
header = b""
while True:
header += self.request.recv(1)
if header and chr(header[-1]) == '}':
break
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, makes me realize we might have added a bit of a bug here with program exiting in general, the old client loop function used to break the websocket loop which implicitly would lead to an exit. My advice it to have one actual sys.exit() point in the program and to reach that point via exceptions.

So I think try: except:-ing around serve_forever is appropriate, with except blocks for KeyboardInterruption, ProgramExit and CommunicationError (or ParseError, you decide) (the last two being exceptions of your own making) and handle them appropriately (for example program exit isn't actually a bad thing, we just want consistent exit strategies)

You should log what you think is best so here's a note about levels:
Will only be seen if someone passed -l to dashmips:

  • debug - for a developer to get detailed insight on the internals of a program (like dump of network traffic)
  • info - verbose information, like entering certain blocks of code or calling functions, intended for someone debugging an issue in production
  • warning - not an error but something that should be corrected

Will always print:

  • critical or error - something unexpected occurred the program cannot continue, this is in the realm of socket port in use, or permission denied, things entirely unfixable by our program

@joshuamitchener joshuamitchener merged commit 568631a into master May 12, 2020
@nbbeeken nbbeeken deleted the debugger_hang_fix branch May 12, 2020 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants