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

Allow ctrl-c to be processed when establishing connection #64

Open
nickchen120235 opened this issue Sep 2, 2024 · 4 comments
Open

Allow ctrl-c to be processed when establishing connection #64

nickchen120235 opened this issue Sep 2, 2024 · 4 comments

Comments

@nickchen120235
Copy link

Version Information

  • OS: Ubuntu Server 24.04
  • Python: 3.12.3
  • openziti SDK: 0.8.1

Current Behavior

Ctrl-C is ignored (maybe?) when the module is trying to establish connection to the ziti network. Today I was playing with the Python SDK and forgot to configure router policy for my identity for the service. I recognized my error when running the script with ZITI_LOG=6 but I cannot Ctrl-C to stop the script.

Expected Behavior

I can stop the script by Ctrl-C even if the script is trying something in the library.

@dovholuknf
Copy link
Member

Could you share your code? Did you add a keyboard interrupt catch and it wasn't triggered? https://docs.python.org/3/library/exceptions.html#KeyboardInterrupt

@nickchen120235
Copy link
Author

nickchen120235 commented Sep 4, 2024

Sure! Here's my code.

import openziti
from http.server import BaseHTTPRequestHandler, HTTPServer

# constants
hostname = "127.0.0.1"
port = "12345"
ziti_config = dict(
  ztx="./identity.json",
  service="python-sdk-server"
)
openziti.monkeypatch(bindings={(hostname, port): ziti_config})

class MyZitiServer(BaseHTTPRequestHandler):
  def do_GET(self):
    self.send_response(200)
    self.send_header('Content-Type', 'text/html')
    self.end_headers()
    self.wfile.write("<h1>Hello from OpenZiti Python SDK</h1>".encode("utf-8"))

if __name__ == "__main__":
  server = HTTPServer((hostname, port), MyZitiServer)
  print(f"Server running on {hostname}:{port}...")
  try:
    server.serve_forever(poll_interval=600)
  except KeyboardInterrupt:
    server.server_close()
    print("Server is closing...")

I also tried the http server example and ctrl-c also didn't work when the library was retrying to connect to my ziti network. The "Server running" line didn't even print so I suspect it's something happening and stuck in the openziti.monkeypatch line.

@ekoby
Copy link
Member

ekoby commented Sep 12, 2024

can you set ZITI_LOG=4 environment variable and post/send the output?

@nickchen120235
Copy link
Author

Sure here's the log https://gist.github.com/nickchen120235/33122b637a4c43472517a8d428626b7d

Note that I purposefully make the edge router not available to the service so that the sdk will try to connect before the Python server is actually started.

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

No branches or pull requests

3 participants