Skip to content

Ensure disconnect called at least once on interface. #1039

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

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions openc3/lib/openc3/interfaces/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,16 @@ def connect
log_dont_log.upcase!
period = "#{period.to_f}s"
@scheduler.every period do
begin
if log_dont_log == 'DONT_LOG'
cmd(cmd_string, log_message: false)
else
cmd(cmd_string)
if connected?()
begin
if log_dont_log == 'DONT_LOG'
cmd(cmd_string, log_message: false)
else
cmd(cmd_string)
end
rescue Exception => err
Logger.error("Error sending periodic cmd(#{cmd_string}):\n#{err.formatted}")
end
rescue Exception => err
Logger.error("Error sending periodic cmd(#{cmd_string}):\n#{err.formatted}")
end
end
end
Expand Down
11 changes: 10 additions & 1 deletion openc3/lib/openc3/microservices/interface_microservice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,16 @@ def handle_connection_lost(err = nil, reconnect: true)

def connect
@logger.info "#{@interface.name}: Connecting ..."
@interface.connect
begin
@interface.connect
rescue Exception => error
begin
@interface.disconnect # Ensure disconnect is called at least once on a partial connect
rescue Exception
# We want to report any connect errors, not disconnect in this case
end
raise error
end
@interface.state = 'CONNECTED'
if @interface_or_router == 'INTERFACE'
InterfaceStatusModel.set(@interface.as_json(:allow_nan => true), scope: @scope)
Expand Down
19 changes: 10 additions & 9 deletions openc3/python/openc3/interfaces/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,16 @@ def protocol_cmd(self, cmd_name, *cmd_args, read_write="READ_WRITE", index=-1):
return handled

def run_periodic_cmd(self, log_dont_log, cmd_string):
try:
if log_dont_log == "DONT_LOG":
cmd(cmd_string, log_message=False)
else:
cmd(cmd_string)
except Exception as error:
Logger.error(
f"Error sending periodic cmd({cmd_string}):\n{traceback.format_exception(error)}"
)
if self.connected():
try:
if log_dont_log == "DONT_LOG":
cmd(cmd_string, log_message=False)
else:
cmd(cmd_string)
except Exception as error:
Logger.error(
f"Error sending periodic cmd({cmd_string}):\n{traceback.format_exception(error)}"
)

def scheduler_thread_body(self):
next_time = time.time()
Expand Down
10 changes: 10 additions & 0 deletions openc3/python/openc3/microservices/interface_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,16 @@ def handle_connection_lost(self, error=None, reconnect=True):

def connect(self):
self.logger.info(f"{self.interface.name}: Connecting :")

try:
self.interface.connect()
except RuntimeError as error:
try:
self.interface.disconnect() # Ensure disconnect is called at least once on a partial connect
except RuntimeError:
pass # We want to report any connect errors, not disconnect in this case
raise error

self.interface.connect()
self.interface.state = "CONNECTED"
if self.interface_or_router == "INTERFACE":
Expand Down