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

Garbage collection does not close connections #151

Closed
guettli opened this issue Dec 5, 2019 · 1 comment
Closed

Garbage collection does not close connections #151

guettli opened this issue Dec 5, 2019 · 1 comment

Comments

@guettli
Copy link
Contributor

guettli commented Dec 5, 2019

From the docs: https://sap.github.io/PyRFC/pyrfc.html#pyrfc.Connection.close

close():
Explicitly close the connection.
Note that this is usually not necessary as the connection will be closed automatically upon object destruction. However, if the the object destruction is delayed by the garbage collection, problems may occur when too many connections are opened.

I think this is not true:

from pyrfc import Connection
import gc

def test():
    connection_dict = ...
    for i in range(1000):
        ping(i, connection_dict)
        gc.collect()

def ping(i, connection_dict):
    conn = Connection(**connection_dict)
    print(i, conn.call('RFC_PING'))


test()

Result after 200 times ping():

Traceback (most recent call last):
  File "tmp/t.py", line 19, in ping
    conn = Connection(**connection_dict)
  File "src/pyrfc/_pyrfc.pyx", line 182, in pyrfc._pyrfc.Connection.__init__
  File "src/pyrfc/_pyrfc.pyx", line 226, in pyrfc._pyrfc.Connection._open
  File "src/pyrfc/_pyrfc.pyx", line 256, in pyrfc._pyrfc.Connection._error
pyrfc._exception.CommunicationError: RFC_COMMUNICATION_FAILURE (rc=1): key=RFC_COMMUNICATION_FAILURE, message=
LOCATION    CPIC (TCP/IP) on local host with Unicode
ERROR       max no of 200 conversations exceeded
TIME        Thu Dec  5 12:59:57 2019
RELEASE     753
COMPONENT   CPIC (TCP/IP) with Unicode
VERSION     3
RC          466
MODULE      /bas/753_REL/src/krn/si/cpic/r3cpic.c
LINE        15830
COUNTER     201
 [MSG: class=, type=, number=, v1-4:=;;;]

The connection object should get closed by the garbage collector which does explicitly closed in above script (gc.collect()).

@bsrdjan bsrdjan closed this as completed in 685912e Mar 9, 2020
@bsrdjan
Copy link
Contributor

bsrdjan commented Mar 9, 2020

Thanks for spotting this. The garbage collection is more often than not delayed and even the explicit deletion of Connection instance is not necessarily triggering the del() method. The comment is therefore updated and free() method added, recommended to call after connection instance not any more needed.

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

2 participants