Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:08:07+00:00 2026-05-11T07:08:07+00:00

I am interested in knowing how databases handle connections that are not explicitly closed

  • 0

I am interested in knowing how databases handle connections that are not explicitly closed by the entity that initiated the connection.

  1. Say I have a database that can accept only 2 concurrent connections at a time. I have a piece of code that opens a connection and never closes it. This piece of code runs forever, but it uses the connection only once in it’s lifetime but the connection object never goes out of scope, so it is not garbage collected. Say I run 2 instances of this code. Does it mean that until the program is terminated or the connection times out (due to inactivity) the database can accept no more connections?

  2. In the above scenario if the connection object is garbage collected, then is the connection terminated automatically or does it depend on the database driver that I am using or the connection is not terminated at all until I close it explicitly?

  3. If I open a connection in piece of code and I do not close the connection explicitly, but the program terminates then how does the database reclaim that connection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:08:08+00:00Added an answer on May 11, 2026 at 7:08 am

    The underlying protocol for database connections is typically TCP/IP based. The connection can be terminated in one of several ways:

    1. The server closes it gracefully and receives an acknowledgement from the client;
    2. The client closes is gracefully and receives an acknowledgement from the server;
    3. The connection times out. The client and server both separately are told by their respective operating systems that the connection has been closed;
    4. The connection is forcefully closed by either side.

    In the case of (3), TCP connections must be kept alive by sending dummy messages every so often to avoid a timeout. Your connection may timeout because neither side is doing this (and for a database connection it’s not something you typically want to do).

    It’s entirely possible for a time for one side to think the connection is closed and hte other side to still believe it is open. Messages may get sent in those cases (and typically discarded).

    Each connection (‘socket’) uses an operating system resource called a file descriptor (in UNIX parlance, your OS may call it something else), which is a handle to an I/O resource and the same thing used for an open file (again, OSs may vary).

    The limit on connections on your database will be the lowest of:

    • The configured limit for the OS;
    • The maximum file descriptors allowed for that process (minus any being used for I/O activity); and
    • (possibly) system settings or policies on connection limits.

    If the connection isn’t TCP based (eg a filesystem socket as is often used with MySQL on UNIX systems) the principles are in fact very simlar.

    Anyway, the moral of the story to take from this is that a database connection–regardless of its form–involves an operating system resource of some kind. Your program hsa directly or indirectly asked for that resource. If the program dies, the operating system will reclaim it (perhaps not immediately but eventually). If the connection gets garbage collected then the resource will be released in much the same way as if it had been forcibly closed.

    Its that external resource (and not the code your client is using) that holds the connection open and drives any limits.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that is interested in knowing when the region of a
I'm interested in knowing how revision-control systems do merging. Suppose you have a file
If I have two tables in a MySQL database that both have a column
Managed languages being the ones that handle memory cleanup for you. EDIT I'm not
I am interested in knowing that what this private API do CGContextSetBaseCTM(CGContextRef c, CGAffineTransform
I am interested in knowing about what other teams are doing about limiting internal
I'm interested in knowing what high quality and useful add-ons or utilities are available
I am new to debugging and I'm very interested in knowing how to setup
I've been programming for some time but never got interested in knowing in theory
I am interested in knowing what the best software would be to build an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.