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

Implement SQL_ATTR_CONNECTION_DEAD for ODBC #9353

Closed
wants to merge 4 commits into from

Conversation

NattyNarwhal
Copy link
Member

This uses the semantically correct SQL_ATTR_CONNECTION_DEAD attribute when possible, and in the event it fails or returns a successful false (since at least for Db2i in some circumstances, may be inaccurate), tries the old heuristic.

May address GH-9347.

This is semantically appropriate and should be used whenever the
driver supports it. In the event that it fails or says the connection
isn't dead (which may be inaccurate in some cases), try the old
heuristic.
This is semantically appropriate and should be used whenever the
driver supports it. In the event that it fails or says the connection
isn't dead (which may be inaccurate in some cases), try the old
heuristic.
zend_hash_str_del(&EG(persistent_list), hashed_details, hashed_len);
goto try_and_get_another_connection;
}
/* If the driver doesn't support it, fall back to old heuristic */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can't we assume that the driver supports SQL_ATTR_CONNECTION_DEAD if ret == SQL_SUCCESS? I mean, can't we skip the fallback (SQL_DATA_SOURCE_READ_ONLY) regardless of the value of dead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the Db2i driver at least had a case where it would return SQL_CD_FALSE, but the heuristic would detect a failed connection. However, that case (specifically, admin killing the database server process) is pretty weird and uncommon (though people bug me enough about it I have to mention it). You're probably right; it'd be better to just trust SQL_ATTR_CONNECTION_DEAD, and get driver authors to implement more accurate results if they're going to use it.

@NattyNarwhal
Copy link
Member Author

FWIW, at least for the Db2i driver, this thread from node-odbc covers some of the specific behaviours of the dead check (and why it's probably a bad idea to do more thorough checks)

@cmb69
Copy link
Member

cmb69 commented Aug 23, 2022

Sigh, ODBC and driver shenanigans! Apparently this is the best we can do. Could you please adjust the comments; it's not only about falling back if SQL_ATTR_CONNECTION_DEAD is not supported, but also if it "returns" false.

@NattyNarwhal
Copy link
Member Author

Could you please adjust the comments; it's not only about falling back if SQL_ATTR_CONNECTION_DEAD is not supported, but also if it "returns" false.

This, or return early if SQL_ATTR_CONNECTION_DEAD is false? I messed up the previous commit so that it doesn't do that (though it is more correct than with it); trusting the driver might be better long-term.

@cmb69
Copy link
Member

cmb69 commented Aug 23, 2022

or return early if SQL_ATTR_CONNECTION_DEAD is false?

Form what I can tell, the liveness checks are only required for persistent connections; I think, we better make sure that we don't get a false positive for this. And from reading the thread you've linked above, it seems to me that SQL_ATTR_CONNECTION_DEAD could easily yield true, although the connection has been gone.

I'm not sure how important persistent connections are for (PDO_)ODBC; I assume that ODBC connection pooling is almost always preferable (certainly for FCGI, where multiple processes won't necessarily share persistent connections).

@NattyNarwhal
Copy link
Member Author

I think there's also a lot of code using persistent connections out of habit when it did matter/help more that hasn't been changed.

That said, it's fair regarding that for user consistency. I don't think the current fallback check is too harmful to run; I just don't want it to accumulate too many checks that could just risk making it work.

@NattyNarwhal
Copy link
Member Author

8.2 feature freeze is tomorrow; do we want to get this in before then?

@cmb69
Copy link
Member

cmb69 commented Aug 29, 2022

8.2 feature freeze is tomorrow

Feature freeze was already shortly before beta1 has been tagged. This doesn't really matter for this PR, since this is a small and self-contained improvement.

Anyhow, thanks for the reminder! I'm going to merge.

@cmb69 cmb69 closed this in f3a14d1 Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants