Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-12-26
09:20 • Closed ticket [1909647fff]: TclStackFree: incorrect freePtr. Call out of sequenc... artifact: 907f5d5273 user: sf-robot
2009-12-11
10:31 • Pending ticket [1909647fff]. artifact: 1cdad19dd9 user: msofer
2009-05-12
14:45 • Open ticket [1909647fff]. artifact: 0236a774b7 user: ctasada
14:45 • Ticket [1909647fff]: 4 changes artifact: 90dfa00a4c user: ctasada
2009-05-10
10:09 • Pending ticket [1909647fff]. artifact: 04b90f7431 user: msofer
10:09 • Ticket [1909647fff]: 4 changes artifact: 7e558fecea user: msofer
2009-01-19
18:46 • Ticket [1909647fff]: 6 changes artifact: 88e3a24e80 user: ctasada
2008-12-11
16:16 • Ticket [1909647fff]: 4 changes artifact: 111b2ebc37 user: ctasada
2008-07-30
14:34 • Ticket [1909647fff]: 4 changes artifact: 445d0cf552 user: ctasada
06:53 • Ticket [1909647fff]: 4 changes artifact: 3be12fd45f user: msofer
2008-07-21
14:40 • Ticket [1909647fff]: 4 changes artifact: 188c07f5a6 user: ctasada
11:49 • Ticket [1909647fff]: 4 changes artifact: a67379015c user: msofer
2008-06-30
15:17 • Open ticket [1909647fff]. artifact: f61a45e650 user: ctasada
2008-06-28
20:43 • Pending ticket [1909647fff]. artifact: d5b25340fc user: msofer
2008-03-11
20:30 • Ticket [1909647fff]: 4 changes artifact: 26e2d2adbf user: msofer
20:14 • Ticket [1909647fff]: 4 changes artifact: e22a98be48 user: ctasada
19:48 • Ticket [1909647fff]: 4 changes artifact: cf60345f28 user: msofer
19:18 • Ticket [1909647fff]: 1 change artifact: 3ebe90b567 user: dkf
2008-03-07
15:47 • New ticket [1909647fff]. artifact: b9b1c8c6eb user: ctasada

TclStackFree: incorrect freePtr. Call out of sequence?

Closed1909647fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 17 years ago
Descriptionplain2008-03-07 15:47:44
Hi guys,

We're using ActiveTcl 8.5.1, bytecoded with tbcload1.7. From time to time, the application crashes with a "TclStackFree: incorrect freePtr. Call out of sequence?", but so far this happens only in Linux.

We're using threads and sockets actively and usually the crash appears just after a "puts" in a file or after a socket is closed.

I don't even known how to start debugging the problem.

I've been looking into Tcl sourcecode and the first think that I see regarding the use of TclStackFree is that it's used in the Linux version of TclpCreateProcess, but not in Windows. Following this lead I finished in the Tcl_OpenCommandChannel, the one used to process the tcl exec command.

Am I in drunks o could be that some error or wrongly synched command in the Tcl_OpenCommandChannel could be producing this problem?

Any help is more than welcome.

Cheers,
Carlos
dkf Ticket [1909647fff]: 1 change [History diff]2008-03-11 19:18:38
msoferplain2008-03-11 19:48:22
Logged In: YES 
user_id=148712
Originator: NO

This definitely looks like a threading problem: wrong timing within the same thread will cause TclStackFree to bomb reliably.

First let us try to reduce the problem a bit:

(1) tbcload should have nothing to do with this; can you confirm by using the script sources instead of the precompiled version? I do not know if you have them available or not, it might be 3rd party code

(2) You are using threads: script or C api? If C: are you respecting Tcl's threading model, "no calls to an interp from a different thread"? 

(3) Can you reduce the problem to some smallish demo that we can study?
ctasadaplain2008-03-11 20:14:56
Logged In: YES 
user_id=340696
Originator: YES

Hi Miguel,

What do you mean by "wrong timing"? Some "after"? or maybe some async thread that's released too early? Can the problem be related with some "exec" command as I said before?

Regarding you questions

1) I already though about that. I doing some changes in the sourcecode and I have a client that volunteer to test it running from source. Hope I'll have something new in a couple of days.

2) I'm using threads from scripts.

3) That's the bad part. I'm trying to find how to simplify the problem as much as possible to have a nice test case. Anyway seems that's related with some other problem that's leaking memory (I'm looking into that right now). At the moment that I "puts" to a file, seems that the used memory is too much and the application crashes.

Best Regards,
Carlos Tasada.
msoferplain2008-03-11 20:30:33
Logged In: YES 
user_id=148712
Originator: NO

On the timing issue: TclStackAlloc/TclStackFree is a very specialised internal allocator, it reserves memory in Tcl's internal stack. It is of the utmost importance for its proper functioning that frees occur in the precise reverse sequence of allocs (*), or else get a panic. What you are seeing is a violation of this timing principle.

Had this happened in a single thread, the crash would be deterministic - an obvious bug with a slim chance of making it past the testing phase. However, if different threads are allocing/freeing from the same interp's stack (shouldn't happen as the stack is interp-specific), thread coordination issues could cause the observed behaviour. This is what I suspect. Not much of a clue beyond that yet.

(*) They should also be precisely coordinated with the bytecode engine's own usage of the stack. This is an internal allocator that is not meant to be used by extensions.
msoferplain2008-06-28 20:43:54
Logged In: YES 
user_id=148712
Originator: NO

Submitter went AWOL? I'm still suspecting a violation of Tcl's threading model. 

In order to do anything about this I would need more info.
ctasadaplain2008-06-30 15:17:34
Logged In: YES 
user_id=340696
Originator: YES

Hi Miguel,

What more info do you need? My main problem is that I cannot replicate the problem in an easy way. But I found some extra info about that. We've the same code running in 32 and 64 bits and seems that the problem happens more frequently in 64b. Anyway just ask me what more info do you need and I'll do anything on my side to send it to you.
msoferplain2008-07-21 11:49:36
Logged In: YES 
user_id=148712
Originator: NO

Sorry this flew under my radar. More info: ideally a smallish example to repro. But at least
(a) assurance that the threading model is respected: each interp is only called from the thread where it was created
(b) a stack trace
ctasadaplain2008-07-21 14:40:12
Logged In: YES 
user_id=340696
Originator: YES

Hi Miguel,

I'll do my best to send you more info this week.

Best Regards,
Carlos.
msoferplain2008-07-30 06:53:19
Logged In: YES 
user_id=148712
Originator: NO

One thing that comes to mind is #2030670. A fix was committed today to both HEAD and the 8.5 branch, that patch can be applied as is.

Hmmm ... I now notice that it is under 8.5.1. The very first thing to do is to test with a more recent version, that could well be a something that's already fixed. However, if it is #2030670 no version containing the patch has yet been released.
ctasadaplain2008-07-30 14:34:46
Logged In: YES 
user_id=340696
Originator: YES

Yes, I saw the patch and also though that could be related :)

Thinks have been crazy here the last weeks, anyway as soon as 8.5.4 is released I'll give it a try :)

Can we leave this bug in standby until then?
ctasadaplain2008-12-11 16:16:47
Hi Miguel,

Well it took me almost 6 months to come back to you (I'm ashamed). We upgraded to 8.5.4 2 months ago, and seemed that everything was fine, but last week I found the same problem again. This time our customer is running a "CentOS release 5.2 (Final) (2.6.18-92.1.13.el5xen) (x86_64 64 bits)"

In a previous email you asked for 2 thinks: 

a) be sure that the thread model is respected

I'm reasonably sure that everything is fine there. But we do, of course, some chitchatting between threads to send and get back results.

b) Stacktrace

How can I do that? Do I need some special Tcl build? (I'm using ActiveTcl 8.5.4)

I'm still without good replication steps. It simply happens so I'm not really sure how to attack it.

Best Regards,
Carlos.
ctasadaplain2009-01-19 18:46:02
Hi Miguel,

Bug appeared again in another machine. And seems to happen with some frequency, so maybe I´ll be able to debug there.

Any tip about how to do it?
msoferplain2009-05-10 10:09:14
Still happening with newer releases?
msofer Pending ticket [1909647fff]. [History diff]2009-05-10 10:09:15
ctasadaplain2009-05-12 14:45:51
Do you mean in the 8.5.7 or in 8.6?

Anyway I haven't seen any crash since January using 8.5.4, but also, as you known, I cannot replicate it easily.

On the other hand I've seen that using linux kernel 2.6.27 I've tons of crashes using threads, but I don't known if it's related or not with this case.

I'll try to create an script to replicate it, but I cannot promise anything in a short time :(

Thanks.
ctasada Open ticket [1909647fff]. [History diff]2009-05-12 14:45:52
msofer Pending ticket [1909647fff]. [History diff]2009-12-11 10:31:06
sf-robotplain2009-12-26 09:20:32
allow_comments - 1

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
Log in (anonymous is fine) to add a comment.