Skip to content

Commit

Permalink
fix(server): server closing deallocation fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrdjan committed Aug 1, 2023
1 parent 4609d72 commit 2c0432b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 3 additions & 4 deletions examples/server/server_pyrfc_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def my_auth_check(func_name=False, request_context=None):


# create server
server = Server({"dest": "gateway"}, {"dest": "MME"}, {"port": 8081, "server_log": False})
server = Server({"dest": "MME_GATEWAY"}, {"dest": "MME"}, { "server_log": True})

# expose python function my_stfc_structure as ABAP function STFC_STRUCTURE, to be called by ABAP system
server.add_function("STFC_STRUCTURE", my_stfc_structure)
Expand All @@ -49,6 +49,5 @@ def my_auth_check(func_name=False, request_context=None):

input("Press Enter to stop server...") # WPS110

# stop server
server.stop()
print("Server stoped")
# shutdown server
server.close()
14 changes: 9 additions & 5 deletions src/pyrfc/_cyrfc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1995,13 +1995,18 @@ cdef class Server:
is delayed by the garbage collection, problems may occur when too many
servers are registered.
"""

if self._server_handle == NULL:
return

self.stop()

# Server connection close
if self._server_handle != NULL:
with nogil:
RfcDestroyServer(self._server_handle, NULL)
self._server_handle = NULL
server_handle = self.server_handle
with nogil:
RfcDestroyServer(self._server_handle, NULL)
self._server_handle = NULL
_server_log("Server", f"{server_handle} closed")

# Remove all installed server functions
global server_functions
Expand All @@ -2010,7 +2015,6 @@ cdef class Server:
if func_data["server"] != self:
after_remove[func_name] = func_data
server_functions = after_remove
_server_log("Server", f"{self.server_handle} closed")

def __dealloc__(self):
self.close()
Expand Down

0 comments on commit 2c0432b

Please sign in to comment.