Sockets remaining open after connection failure

Hi - I have a multithreaded application that runs as a daemon (always up) and uses OCI (10.2.0, 64-bit client). If a database connection or query fails for any reason, it is coded to keep on retrying on a set schedule until it succeeds. The application runs on RHEL 4 (64-bit) and is compiled with g++ 3.4.6. (It's nominally C++, but is really what I call "C with objects" as it doesn't use a lot of the standard C++-isms, though there are objects -- the OCI code in question is in a C++ object wrapper that I wrote.)
Anyway, about 5 days ago, the database where most of the queries are run went down (it's a 10g server; I don't remember the exact version, but since it's down, I'm not sure it matters), and it has not come back up, although the hosts it runs on are up. Meanwhile, my application kept failing to connect and retrying, and the number of queries that this was happening to kept on growing as new ones are added every day. Unknown to me, the failed connection attempts were leaving open TCP sockets to the database that was down, until eventually the maximum open files on the system was exceeded and I was forced to reboot. Twice. (It happened again the next day.)
From what I can tell, I am properly dropping the handles and such when a connection fails, so why are the sockets staying open? Is there anything that can be done to force the socket to close after a failed connect? This morning I changed all the queries to use a different database (that's actually up), but according to lsof, there are still 56 open sockets to the old (non-working) database, even though none of my program threads are actively trying to connect there anymore.
The sockets do close, by the way, if the application is stopped and restarted. But they remain open as long as the instance that created them is still running. (I added a periodic restart to clean things up, but I'd really like to fix the problem instead of using a stopgap like this!)
Sample code is below. This first bit is what is used to connect and log in. (Note that I have this mutex-locked -- I know OCI is supposed to be thread-safe if you use the OCI_THREADED attribute, but I've been having so many issues that I thought it was safer.)
if (check_err(OCIEnvCreate(&env, (OCI_THREADED), (void *) 0, 0, 0, 0, (size_t) 0, (void **) 0)) != 0)
fprintf(stderr, "Error allocating OCI environment handle\n");
return;
// Allocate error handle.
if (check_err(OCIHandleAlloc((void *) env, (void **) &err, OCI_HTYPE_ERROR, 0, (void **) 0)) != 0)
fprintf(stderr, "Error creating OCI error handle.\n");
return;
// Allocate server handle.
if (check_err(OCIHandleAlloc((void *) env, (void **) &server, OCI_HTYPE_SERVER, 0, (void **) 0)) != 0)
fprintf(stderr, "Error allocating OCI server handle.\n");
return;
// Allocate service handle.
if (check_err(OCIHandleAlloc((void *) env, (void **) &svc, OCI_HTYPE_SVCCTX, 0, (void **) 0)) != 0)
fprintf(stderr, "Error allocating OCI service handle.\n");
return;
[Note: these are snippets from two different functions; this is a C++ wrapper that uses OCI, so the above code is in the database object constructor, and below is a separate login function.]
// Attach to server.
retcode = OCIServerAttach(server, err, (text *) curDS, strlen(curDS), OCI_DEFAULT);
if (check_err(retcode))
fprintf(stderr, "Error attaching to Oracle server.\n");
return(retcode);
// Set server attribute in service handle.
retcode = OCIAttrSet((void *) svc, OCI_HTYPE_SVCCTX, (void *) server, 0, OCI_ATTR_SERVER, err);
if (check_err(retcode))
fprintf(stderr, "Error setting OCI server attribute.\n");
return(retcode);
// Allocate session handle.
retcode = OCIHandleAlloc((void *) env, (void **) &sess, OCI_HTYPE_SESSION, 0, (void **) 0);
if (check_err(retcode))
fprintf(stderr, "Error allocating OCI session handle.\n");
return(retcode);
// Set username attribute in session handle.
retcode = OCIAttrSet((void *) sess, OCI_HTYPE_SESSION, (void *) curUser, strlen(curUser), OCI_ATTR_USERNAME, err);
if (check_err(retcode))
fprintf(stderr, "Error setting OCI username.\n");
return(retcode);
// Set password attribute in session handle.
retcode = OCIAttrSet((void *) sess, OCI_HTYPE_SESSION, (void *) curPass, strlen(curPass), OCI_ATTR_PASSWORD, err);
if (check_err(retcode))
fprintf(stderr, "Error setting OCI password.\n");
return(retcode);
// Start session.
retcode = OCISessionBegin(svc, err, sess, OCI_CRED_RDBMS, OCI_DEFAULT);
if (check_err(retcode) != 0)
return(retcode);
// Set session attribute in service handle
retcode = OCIAttrSet((void *) svc, OCI_HTYPE_SVCCTX, (void *) sess, 0, OCI_ATTR_SESSION, err);
if (check_err(retcode))
fprintf(stderr, "Error setting OCI session attribute.\n");
return(retcode);
If any of the above calls returns an error, the next call is to the database object destructor (also mutexed), which looks like this:
if (connected && svc && err && sess && check_err(OCISessionEnd(svc, err, sess, OCI_DEFAULT)))
fprintf(stderr, "Oracle - Error ending session\n");
if (connected && server && err && check_err(OCIServerDetach(server, err, OCI_DEFAULT)))
fprintf(stderr, "Oracle - Error detaching from server\n");
if (connected && server && check_err(OCIHandleFree((void *) server, OCI_HTYPE_SERVER)))
fprintf(stderr, "Oracle - Error freeing server handle\n");
if (connected && svc && check_err(OCIHandleFree((void *) svc, OCI_HTYPE_SVCCTX)))
fprintf(stderr, "Oracle - Error freeing service handle\n");
if (connected && err && check_err(OCIHandleFree((void *) err, OCI_HTYPE_ERROR)))
fprintf(stderr, "Oracle - Error freeing error handle\n");
if (connected && env && check_err(OCIHandleFree((void *) env, OCI_HTYPE_ENV)))
fprintf(stderr, "Oracle - Error freeing environment handle\n");
Anyone else had this happen? Any insights/help would be greatly appreciated!
Oh, one more note: though the application is multithreaded, none of the database objects or connections is shared -- each thread makes its own connections and maintains database objects separately. I added the mutex locks because Helgrind was reporting race conditions on handle allocations and deallocations.
Thanks,
--Tina                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Hmm, I believe I did have an OCIHandleFree on the session handle in an earlier version of the code. I can't remember why I took it out, but I do remember that there was a reason -- it was causing a problem. (Yeah, I know, vague enough for ya?) Anyway, the OCI documentation said that when you call OCIHandleFree on the environment handle, any child handles would be implicitly freed, so I assumed it wouldn't be a problem. Still, I'll try putting it back and see what happens. Thanks.
Oh, and to answer your question (about netstat), it said the processes were ESTABLISHED. But the Oracle server was down (although the hosts it resided on were up). The connection attempt failed with the error message:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Message was edited by:
user613364

Similar Messages

  • How do i get the download window to remain open after closing firefox browser window

    i sometimes download a bunch of files all at ones then have to go back to review them. but i don't need the browser open to do this just the download window. in older versions the download window would remain open after i closed the browser but i don't see a way to do that anymore?

    You can set the pref browser.download.manager.quitBehavior to 2 on the about:config page.
    See http://kb.mozillazine.org/browser.download.manager.quitBehavior
    To open the <i>about:config</i> page, type <b>about:config</b> in the location (address) bar and press the "<i>Enter</i>" key, just like you type the url of a website to open a website.<br />
    If you see a warning then you can confirm that you want to access that page.<br />

  • Socket stays open after java process exits, Runtime.exec()

    I have a program that does the following:
    opens a socket
    Does a runtime.exec() of another program
    then the main program exits.
    what i am seeing is, as long as the exec'd program is running, the socket remains open.
    What can i do to get the socket to close?
    I even tried to explicity call close() on it, and that didn't work. Any ideas would be great.
    I am running this on WindowsXP using netstat to monitor the port utilization.
    here is some sample code
    import java.io.*;
    import java.net.*;
    public class ForkTest
        public static void main(String[] args)
            try
                DatagramSocket s = new DatagramSocket(2006);
                Process p = Runtime.getRuntime().exec("notepad.exe");
                System.out.println("Press any key to exit");
                System.in.read();
            catch (IOException ex)
                ex.printStackTrace();
    }

    java.net.BindException: Address already in use: Cannot bind
            at java.net.PlainDatagramSocketImpl.bind(Native Method)
            at java.net.DatagramSocket.bind(DatagramSocket.java:368)
            at java.net.DatagramSocket.<init>(DatagramSocket.java:210)
            at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
            at java.net.DatagramSocket.<init>(DatagramSocket.java:234)
            at ForkTest.main(ForkTest.java:11)

  • Cursors remained open after closing connection

    I am using OC4J 10g (Application Server) and Oracle10g DB. OC4J is maintaining the connection pool(com.evermind.sql.DriverManagerDataSource). I get the connection from pool and call DB procedure, then close resultset, statement and connection. It closes the opened cursors against resultset. But left some implicit cursors opened and never closed so cursor count is going to increase.
    If i dont use pool no cursor remained open and count is zero. It means the cursors of pooled connections are not closed.
    wait-timeout="60"
    min-connections="5"
    max-connections="100"
    inactivity-timeout="15"
    <property name="stmt-cache-size" value="2000"/>
    Tahir

    Hi Justin,
    Thnx for your reply and you're understanding is correct but the problem I face is when multiple concurrent users access the JSP page from which I'm actually calling the servlet to retrieve the image, the number of cursors being left open increases. As the load on the page increases (i.e. no of usesrs increase) oracle seems to have problems in garbage collecting the open cursors ... which eventually leads it to throw maximum cursors exceeded exceptions.
    Any suggestions ?
    -Athar

  • ODBC connection remains open after disconnect

    Hello,
    in my application I use 2 ODBC connects to 2 different ODBC drivers.
    My problem:
    When I close one connection (with DBDisconnect), the connection on the database remains open until I close the second one.
    Is this a known behavior?
    Is there a way to force the closing or to make it independant of the other connection?
    Regards
    Fred
    Solved!
    Go to Solution.

    As ODBC connections are not inherently included in the CVI environment, I looked up the DBDisconnect function and it says that the DBDisconnect function disconnects the last connected ODBC database. So it is expected behavior.
    Ian M.
    National Instruments

  • Adobe XI remains open after printing from command line

    I am using a program to collect, batch print and delete multiple PDF files.
    The following command line is used to print the files, after which the file is deleted and next file is collected.
         "C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe" /T /N FileName.pdf
    I have now upgraded to Adobe XI, however Adobe remains open (and minimized) after sending the print job to the printer, resulting in my programing freezing while waiting to delete.
    Is there a parameter to close Adobe after printing?
    This is rather urgent as we have started rolling out the new Adobe XI.
    OS = Windows7 Prof x64

    Command line parameters are sparsely documented and are officially not supported. What is documented can be found here: http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/intro_to_sdk/DeveloperFAQ.pd f
    I've not seen anything that shows what you want to do.

  • Mapped drives do not open after connecting via Cisco VPN Client

    I have an issue when I initially connect to my remote network, I cannot get to any mapped drive unless I wait a few minutes for the VPN connect to mature. To explain further, I have to wait 2-4 minutes after connecting to the VPN for me to actually connect to those drives.
    The error that pops up is:
    "An error occurred while reconnecting to DriveLetter: to \\Server\sharedDrive\    Microsoft WIndows Network: The network path was not found. This connection has not been restored.
    Now, immediately after  I connect, I am able to successfully ping the server that hosts those folder locations but for some reason I cannot get to the server via UNC/shared drives until I wait a few minutes after connecting. 
    Below is the list of error logs I get when attempting to connect to the mapped drives during those first few minutes of connectivity:
    1      15:26:39.804  10/06/14  Sev=Warning/3 IKE/0xA300005F
    Firewall, Sygate Security Agent, is not running, the client will not send firewall information to concentrator.
    2      15:28:10.614  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    3      15:28:10.614  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    4      15:28:10.614  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    5      15:28:10.614  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    6      15:28:10.614  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    7      15:28:10.614  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    8      15:28:10.614  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    9      15:28:10.614  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    10     15:28:17.188  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    11     15:28:17.188  10/06/14  Sev=Warning/2 IPSEC/0xE3700003
    Function CniInjectSend() failed with an error code of 0xE4510023 (IPSecDrvCB:856)
    12     15:33:50.642  10/06/14  Sev=Warning/2 CVPND/0xA3400015
    Error with call to IpHlpApi.DLL: CheckUpVASettings: Found IPADDR entry addr=192.168.11.120, error 0
    13     15:33:51.656  10/06/14  Sev=Warning/2 CVPND/0xA3400015
    Error with call to IpHlpApi.DLL: CleanUpVASettings: Was able to delete all VA settings after all, error 0
    14     15:35:16.855  10/06/14  Sev=Warning/3 IKE/0xA300005F
    Firewall, Sygate Security Agent, is not running, the client will not send firewall information to concentrator.
    Any ideas on what it could be?

    I have a client that is showing a similar issue.. Windows 7 computer using Cisco IPSec client terminating on a Cisco 881 Router.  I can ping the server by IP, Name and even access the drive from the start menu option, but not the mapped drive.  Currently I am looking into this from a offline file issue in windows, but ran across this post and was wondering if you had figured this out?  I am going to try the following and will post back if that resolves it.
    Doing some research I found that Windows 7 and Vista both have what’s called “slow link mode”.  The behavior is that if the latency of the network connection exceeds 80 milliseconds (ms), the system will transition the files to “offline mode”.  The 80 ms value is configurable using a local group policy edit.
    Open Group policy (start -> run -> gpedit.msc)
    Expand “Computer Configuration”
    Expand “Administrative Templates”
    Expand “Network”
    Click on “Offline Files”
    Locate “Configure slow-link mode”
    This policy can either be disabled or set to a higher value for slower connections.
    https://www.conetrix.com/Blog/post/Fixing-Problem-With-Windows-7-Shared-Files-and-Mapped-Drives-Unavailable-Over-VPN.aspx

  • Why do ports remain open after closing Firefox?

    I have noticed recently that several ports associated with Firefox remain open when the Firefox browser is closed. The number of open ports increases each time Firefox is opened and I have seen that the number of open ports has reached to more than 1,000 open ports at a time. The majority of the open ports are outbound TCP using port 443 and I also note a sustained increase in the network traffic after Firefox is closed.
    I have observed ports opened by the Explorer browser and noted that all of the ports opened with Explorer close when the Explorer browser is closed. The Firefox ports remain open when the browser is closed.
    Questions:
    - Should all open ports associated with an open Firefox browser close when the Firefox browser is closed?
    - Does Firefox have a setting that closes all open ports when the Firefox browser is closed?
    - Does XP have a setting that will close all open ports associated with Firefox when Firefox is closed?
    - Should I have security concerns about the accumulating open ports and increased network activity when using Firefox?
    Thanks.

    You can set the pref browser.download.manager.quitBehavior to 2 on the about:config page.
    See http://kb.mozillazine.org/browser.download.manager.quitBehavior
    To open the <i>about:config</i> page, type <b>about:config</b> in the location (address) bar and press the "<i>Enter</i>" key, just like you type the url of a website to open a website.<br />
    If you see a warning then you can confirm that you want to access that page.<br />

  • My Firefox.exe process remain open after I close the browser.If I open it it's says to open a new window.I need to close the process manualy(Ctrl+Alt+del).What can I do?Thanks .

    Need to close the process.

    It does take Firefox a while to shut down; it has to update some databases. But it should take less than a minute.
    In the support article, this problem is called a "hang at exit" because Firefox hangs when shutting down. Maybe something here will help: https://support.mozilla.com/en-US/kb/Firefox+hangs#Hang_at_exit
    Also, sometimes open Firefox windows disappear from the Task Bar. You can use Alt+Tab to switch to them if they remain open.

  • "file upload" window remains open after selecting a file. Have to "force quit" to get it to go away. How can I fix this?

    Every time I try to upload a file, the "file upload" window remains open and will not go away unless I force quit Firefox. The window stays in front of all other programs and applications. Is this a problem with Firefox or with OSX? Any idea how to solve it? I've tried clearing the cache & cookies, etc. Should I reinstall Firefox or is there a simpler solution?

    On Windows (don't know about Mac), the latest version will always take over the file association, and become the default for indd files. It's impossible to change it.
    But there is a plugin for ID that makes this possible. Never tried it myself.
    https://www.rorohiko.com/wordpress/downloads/lightning-brain-soxy/

  • SQL Connections remain open after Crystal Report closes

    I am wirting an interface to use the crystal report viewer to print reports, connecting to a Progress Open Edge 10.1B database.  From our application we declare the application, report, exportoptions and connectionproperties objects and pass these to the crystal reports viewer.  Once the report is printed we release the objects and set their variables for null.  However we are finding that the SQL connection to the database is remaining connected and we can only release the connection by manually going in a disconnecting.
    I have read in forums that people use .dispose or .close to release the connection, however we do not have access to these methods as we do not use .NET.  Are there any methods we can use to disconnect these sql connections?

    Hi Dean,
    Moved to the Legacy Application forums. Likely using the RDC as your report engine.
    You should still be able to close and dispose of the report objects. They are not specific to .NET.
    In VB it would look something like these lines::
        crReport.Close
        Set CrystalActiveXReportViewer1.ReportSource = Nothing
        Set crReport = Nothing
    Once the report is closed it should disconnect from the DB. If you close the application does that disconnect?
    Have you looked on 4GL's site for info on how to?
    Thank you
    Don

  • Database connection remains open after close being called

    I am using oracle OC4J as my application server. I am not using connection pool and I am using non-pooled datasource to get connection. The database connection is made at runtime and then closed. I want to test if the users' connection sessions have been killed after they logout the application. But when I checked the table v$session in the database, it shows one connection remaining. I checked my program, the close method has been called. Does anybody know the solution?

    Hi Chen,
    This is just a suggestion for something to try -- only if you haven't
    already tried it, that is!
    Try running OC4J in "debug" mode. Here are details on how to do that:
    http://kb.atlassian.com/content/atlassian/howto/orionproperties.jsp
    Hope this helps you!
    Good Luck,
    Avi.

  • RFC Connection remains open after portal logoff

    Hi,
    We have configured Universal Worklist in our EP7 EHP1 SPS4 Portal.
    When a user connects to the Portal and launches the UWL it creates an RFC connection to the backend ECC. However, when the user moves away from UWL iview or logs out or closes the browser the RFC connection in the backend still
    remains and is released only after the timeout value reached as set in ECC.
    Are there any settings on the portal or ECC to release the session immediately once  user moves away from UWL or logs out of portal ?
    Thanks,
    Savy.

    Hi my friend
    It costs time and resources to establish an RFC connection, therefore it is not immediately deleted but maintained by the system to be reused. But in case there're special purpose to control RFCs, here're 2 parameters to do so:
    The parameter gw/gw_disconnect is a timeout in seconds to close the TCP connection between two SAP gateways if there is no RFC connetion on it for the given timeout. But if there is an active RFC connection onit it will not be closed even if there is no traffic on that RFC connection. Thats why you need another parameter.
    The parameter gw/keepalive is used to periodically check all active RFC (and other) gateway connections if there was no traffic on them for the given time.
    Regards,

  • ITunes doesn't auto. open after connecting iPhone

    Everytime i connect my iPhone 3G to my iMac (v.10.4.11), iTunes(v.7,7,1)
    does not open automatically, instead iPhoto is opening by itself.
    It also does not appear in the sidebar of my Finder, or is this normal ???
    Any helpful idea???
    Thanks in advance.

    RoMYI,
    The iPhone will launch iPhoto if it has pictures taken on the iPhone. You can change this setting in iPhoto '08 or in Image Capture.
    The iPhone does not support disk mode, so will not show up in the sidebar in Finder.
    If you open iTunes does it show up in iTunes, and what options are checked in the Summary tab?
    Thank you,
    Nathan C.

  • [Solved] KDM will not open after power failure

    Had a power failure and upon reboot, I get the following error:
    cannot open theme file
    /usr/share/apps/kdm/themes/archlinux-simplyblack
    I cd'd to the above path but only 'circles' and 'oxygen' are in the themes folder.
    I even ran pacman -S kde to reinstall all the kde packages, but no luck.
    Any ideas on a fix?
    Thanks!
    Last edited by SkinnyJ (2009-05-05 02:15:53)

    glad it works now, if you're using ext4 i hear power failures can corrupt some files; otherwise, i dunno.
    anyway, please mark as [solved].  and thanks for the bit about my enemies .

Maybe you are looking for