Rocket U2 | UniVerse & UniData

 View Only

 Restore uopy session after health_check returning false

Héctor Cortiguera's profile image
Héctor Cortiguera posted 11-21-2024 04:02

Hi all

I'm trying to replicate some legacy code using uopy, but I've found an issue that's hard to solve.

This is a LONG process, both server and local side, so timeouts may appear. Using the older UVIC32.dll code we can simply reconnect to a session after it has been closed by the server. But, after health_check returns false to uopy I can't reconnect to the server, and the connect() method is not connecting.

Is there a way to do this?

John Jenkins's profile image
John Jenkins

Hector,

Could the process be kicked off as a PHANTOM (You could then use application-level socket communications) or as a web service? Network connections can be lost for a large number of reasons, and a disconnected end point usually means that session is history with very few exceptions. A middle-tier such as a RESTful web service would seem ideal here.

Regards

JJ

Héctor Cortiguera's profile image
Héctor Cortiguera

Hi John

The issue I have is that this code doesn't necessarily run on a Universe server, hence using uopy to connect from an external machine.

On the uopy side we connect to a Universe server, run some commands, manage files, but also we do a lot of client-side processing. So, on servers with small timeouts we can find ourselves with a dead session.

The issue was non-existen using UVIC32 code, because if a session was closed we could reopen it on the spot. But, with uopy, this is not as easy as the connections are done inside a python with block, so I have to exit that block and recreate a new session object:

with uopy.connect(host=..., user=..., password=..., account=...) as session:
    # here my session is active
    ...
    if not session.check_health();
        # what can I do?

John Jenkins's profile image
John Jenkins

Hector,

A UOPY session is just a  different client language interface to UniObjects,  and when a  connection is closed (whatever the reason) then the session would terminate on the server - as by design and as if a TELNET connection were to drop. 

I still recomm;nd using a Web Service on the UniVerse server for the task and putting the Python behind the Web Service. While you could launch your own PHANTOM as a 'wrapper' on the UniVerse server itself to run the Python code - and use own-code socket communication the work involved. This is all supported by the UniVerse socket APIs and the client can be anything that supports socket communiafions.

Your Rocket SE contact should be able to advise on the mechanisms involved in a setting up a Web Service and maybe give a 'live' demo.

Unfortunately, I don't see a way to reconnect to a UOPY server process when the client terminates or the network connection is lost - the server process would terminate almost immediately once the connection was lost. Only a PHANTOM using own-code socket communitions can offer peer-to-peer reconnection functionality. 

Sorry I couldn;t assist with re-connection to a lost UOPY direct database connection.

Regards

JJ

Héctor Cortiguera's profile image
Héctor Cortiguera

I've been tinkering with the uopy session and I've found a way to reconnect after losing connection.

First, we need to fix the value of is_active:

>>>session.health_check()
False
>>>session.is_active
True
>>>session.is_active = False

Because the method connect() won't work while the session is active

Then we need to reset the password in the config dictionary. But we have to access the _config "protected" method, as session.config is a deepcopy and changes won't be reflected on the real session.

>>>session._config['password'] = '...'

Then we can reconnect

>>>session.connect()
>>>session.health_check()
True