Quantcast

Fw: [ pywin32-Bugs-3292681 ] adodbapi - Subtle crash

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Fw: [ pywin32-Bugs-3292681 ] adodbapi - Subtle crash

Vernon D. Cole
I am cross-posting this message from the sourceforge bugtracker, so that everyone will know about it. Perhaps someone will have a clue what might be causing it. It's pretty weird...
v v v v v v v v v v v
From: SourceForge.net <[hidden email]>
Subject: [ pywin32-Bugs-3292681 ] adodbapi - Subtle crash
To: [hidden email]
Date: Tuesday, April 26, 2011, 3:11 PM

Bugs item #3292681, was opened at 2011-04-25 15:51
[... snip ...]
Category: adodbapi
Group: None
Status: [Accepted]
Resolution: None
Priority: 5
Private: No
Submitted By: https://www.google.com/accounts ()
Assigned to: Vernon Cole (kf7xm)
Summary: adodbapi - Subtle crash

Initial Comment:
There is a subtle crash that can occur related to time.sleep(>10) and adodbapi.connect() calls, the second time will crash,
attached there is the simplest test case to crash it and various comments explaining the crash behavior test enviroement and stacktraces.

i hope will be useful to find the right solution, i've only found a bad workarond, without calling adodbapi.close() the crash doesn't happens.

thank you in advice

----------------------------------------------------------------------

>Comment By: https://www.google.com/accounts ()
Date: 2011-04-26 21:11

Message:
The connection string needs sqlserver express installed on the machine, but
the same happens also with oracle oledb provider, this are the two
providers i've tested on, but could be the crash occurs with any provider
-------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2011-04-26 03:19

Message:
I haven't had a chance to repro this yet as the connection string doesn't
work on my dev box.
<span onmouseout="cancel = false; window.setTimeout(WRCHideContent, 1000);" onmouseover="WRCShowContent({&#39;rating&#39;:{&#39;value&#39;:89,&#39;weight&#39;:100},&#39;flags&#39;:{},&#39;ttl&#39;:3600,&#39;expireTime&#39;:&#39;20110428111148&#39;}, this.className);" class="wrc13" style="padding-right: 16px; width: 16px; height: 16px;"><span onmouseout="cancel = false; window.setTimeout(WRCHideContent, 1000);" onmouseover="WRCShowContent({&#39;rating&#39;:{&#39;value&#39;:89,&#39;weight&#39;:100},&#39;flags&#39;:{},&#39;ttl&#39;:3600,&#39;expireTime&#39;:&#39;20110428111148&#39;}, this.className);" class="wrc13" style="padding-right: 16px; width: 16px; height: 16px;"><span onmouseout="cancel = false; window.setTimeout(WRCHideContent, 1000);" onmouseover="WRCShowContent({&#39;rating&#39;:{&#39;value&#39;:94,&#39;weight&#39;:100},&#39;flags&#39;:{&#39;it&#39;:1},&#39;ttl&#39;:3600,&#39;expireTime&#39;:&#39;20110428111914&#39;}, this.className);" class="wrc13" style="padding-right: 16px; width: 16px; height: 16px;">^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
I have downloaded the code and determined that it also crashes on my Vista 32 bit laptop, running either Python 2.7 or 3.2.
It also crashes when using the JET data provider to open an ACCESS .mdb database, so the problem is not specific to any provider.
It DOES NOT crash when using IronPython.
It DOES NOT crash if you have made opened and closed a connection for less than 10 seconds before you try it with the 10 second pause.
It also crashes if the time.sleep(10) call is replaced by sys.stdin.readline() and counting ten seconds, so it's not an interaction with the time() module.

I'll continue looking, but frankly don't have a clue where to start. Brilliant helpers are invited to contribute.
--
Vernon

<div onmouseout="cancel = false; window.setTimeout(WRCHideContent, 1000);" onmouseover="cancel = true;" style="" id="wrchoverdiv">
<img class="hline" src="chrome://wrc/skin/png/line-dark-horizontal.png">
Overall rating
<img class="hline" src="chrome://wrc/skin/png/line-dark-horizontal.png">
<img class="hline" src="chrome://wrc/skin/png/line-dark-horizontal.png">
 

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Fw: [ pywin32-Bugs-3292681 ] adodbapi - Subtle crash

Vernon D. Cole
I found two fixes for the crash.  Now I need one of you brilliant folks to tell me which is correct. First, here is a snippet from adodbapi.
Look closely at the comments on the last three lines of code ...
v v v v v v v v v
[... Snip ...]
[   (Note: lines below are paraphrased -- not quite the actual code) ]
def connect(connection_string):
    pythoncom.CoInitialize()
    conn = win32com.client.Dispatch("ADODB.Connection")
    conn.ConnectionString = connection_string
    conn.Open()
    return Connection(conn)  

class Connection(object):
    __init__(self,conn):
        self.adoConn = conn
        self.messages = []

[... snip ...]
   def _closeAdoConnection(self):                  #all v2.1 Rose
        """close the underlying ADO Connection object,
           rolling it back first if it supports transactions."""
        if self.supportsTransactions:
            self.adoConn.RollbackTrans()
        self.adoConn.Close()

    def close(self):
        self.messages=[]
        try:
            self._closeAdoConnection()                      #v2.1 Rose
        except (Exception), e:
            self._raiseConnectionError(InternalError,e)

        del self.adoConn                                       #### adding this line cures the crash
                                                                       #### or
        pythoncom.CoUninitialize()                        #### removing this line cures the crash
^ ^ ^ ^ ^ ^ ^ ^ ^ ^

So --- which is the correct correction?
remove the CoUininitialize()
or perform the explicit del of the Dispatch object?
---
Vernon


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Fw: [ pywin32-Bugs-3292681 ] adodbapi - Subtle crash

Mark Hammond-4
On 29/04/2011 7:07 AM, Vernon Cole wrote:

> I found two fixes for the crash.  Now I need one of you brilliant folks
> to tell me which is correct. First, here is a snippet from adodbapi.
> Look closely at the comments on the last three lines of code ...
> v v v v v v v v v
>     def _closeAdoConnection(self):                  #all v2.1 Rose
> """close the underlying ADO Connection object,
>             rolling it back first if it supports transactions."""
>          if self.supportsTransactions:
>              self.adoConn.RollbackTrans()
>          self.adoConn.Close()
>
>      def close(self):
>          self.messages=[]
>          try:
>              self._closeAdoConnection()                      #v2.1 Rose
>          except (Exception), e:
>              self._raiseConnectionError(InternalError,e)
>
>          del self.adoConn                                       ####
> adding this line cures the crash
>
> #### or
>          pythoncom.CoUninitialize()                        #### removing
> this line cures the crash
> ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
>
> So --- which is the correct correction?
> remove the CoUininitialize()
> or perform the explicit del of the Dispatch object?

It sounds like the problem is that the object is still alive once
CoUninitialize() is called - then, when the adoCon object is finally
released (when the Connection object itself is released) "bad things"
(tm) happen.  I think that is likely to be considered expected behaviour
- things should all be released before doing a CoUninitialize().

I'd suggest that something like self.adoConn = None in one of the close
methods is perfectly reasonable.   OTOH, I expect the benefits of
uninitializing are probably fairly small, so never uninitializing will
probably not cause any problems.  Resetting the object to None (or
del'ing it) is probably preferred though - if the object remains alive
and is cleaned up while the Python interpreter is finalizing I'd expect
things could still go wrong, and discarding the object completely at
close time seems sensible anyway.

If you can give me a connection string that is likely to fail for me, I
can run the example in a debug version of Python and check there isn't
some other bug in pywin32 or similar which could mitigate the entire
issue...

Thanks!

Mark
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Loading...