@@ -1042,17 +1042,37 @@ cnx_detach(pTHX_ imp_dbh_t * imp_dbh)
1042
1042
1043
1043
sword status = OCI_SUCCESS ;
1044
1044
1045
- // GLOBAL Perl END's may cause these to SEGV doe to filehandles (just a guess).
1046
- // The person thay left off the logging in the first place should have provided a clue
1047
- // assuming thay knew what the issue was.
1045
+ // GLOBAL Perl END's may cause these to SEGV due to filehandles (just a guess).
1046
+ // Also forking can cause duplicate closings of a session. A preexisting handle in
1047
+ // the parent is duplicated in the child. The first process to call SessionEnd
1048
+ // wins, each successive call returns OCI_ERROR.
1049
+ //
1050
+ // The prior author included a comment about errors but was not specific and choose to ignore them.
1051
+ //
1048
1052
// I thought I was being clever by adding the logging to these OCI calls;
1049
- // or at least help to debug the original SEGV issue.
1053
+ // to help debug the original SEGV issue. Best guess is the logging relies on
1054
+ // the filehandles being valid and they are not always valid, hence the SEGV
1055
+ // within Perl's IO printing.
1056
+ //
1057
+ // The OCI calls are successful but the logging is not. I don't like silent failures
1058
+ // so we'll use a more direct approach to handle this; keeping Perl and it's state
1059
+ // out of the picture.
1050
1060
1051
1061
// OCISessionEnd_log_stat( imp_dbh, imp_dbh->svchp, imp_dbh->errhp, imp_dbh->seshp, OCI_DEFAULT, status );
1052
1062
// OCIServerDetach_log_stat( imp_dbh, imp_dbh->srvhp, imp_dbh->errhp, OCI_DEFAULT, status );
1053
1063
1054
- OCISessionEnd ( imp_dbh -> svchp , imp_dbh -> errhp , imp_dbh -> seshp , OCI_DEFAULT );
1055
- OCIServerDetach ( imp_dbh -> srvhp , imp_dbh -> errhp , OCI_DEFAULT );
1064
+ if (( status = OCISessionEnd ( imp_dbh -> svchp , imp_dbh -> errhp , imp_dbh -> seshp , OCI_DEFAULT )) != OCI_SUCCESS
1065
+ && status != OCI_ERROR )
1066
+ {
1067
+ // by printing the pointers I could see the children and parent were
1068
+ // using the same handles. The first is successful, the rest fail. (seems reasonable enough)
1069
+ fprintf ( stderr , "OCISessionEnd() failed: %d %p %p %p pid=%d\n" , status , imp_dbh -> svchp , imp_dbh -> errhp , imp_dbh -> seshp , getpid ());
1070
+ }
1071
+
1072
+ if (( status = OCIServerDetach ( imp_dbh -> srvhp , imp_dbh -> errhp , OCI_DEFAULT )) != OCI_SUCCESS )
1073
+ {
1074
+ fprintf ( stderr , "OCIServerDetach() failed: %d pid=%d\n" , status , getpid ());
1075
+ }
1056
1076
1057
1077
#ifdef ORA_OCI_112
1058
1078
}
0 commit comments