Summary
gc goes crazy with faulty finalizers
Metadata
- Id: b5051f1b787ffa11cf134630057e4edc775eca60
- Trac id: 866
- Type: defect
- Reporter: megane
- Owner: felix
- Cc:
- Status: closed
- Component: core libraries
- Estimated difficulty:
- Resolution: fixed
- Priority: major
- Milestone: 4.9.0
- Version: 4.7.x
- Changetime: 2012-09-24 21:47:48 UTC
- Created: 2012-06-13 10:46:22 UTC
- Keywords:
Attachments
- b5051f1b787ffa11cf134630057e4edc775eca60/attachments/0001-Catch-exceptions-in-finalizers-and-added-tests.patch
Description
;; It seems like the gc stops working correctly after an exception
;; from a faulty finalizer gets caught (and not crash the whole
;; program).
(define n 2000000000)
(define vector-size 100)
(define (make-objects n gc-msg)
(let loop [(i 0)]
(let [(o (make-vector vector-size))]
(print "making " i)
(set-finalizer! o (lambda (ob) (print gc-msg " " i)))
(if (< i n)
(loop (+ 1 i))))))
(set-finalizer! (make-vector 100) (lambda (ob) (+ i 'a)))
(handle-exceptions
exn
(begin
(print "Caught an exception" exn))
(make-objects n "gc'ing"))
(print "done")
;; Result when compiled: 3 cases
;; Case 1: out of memory, tweak n, vector-size to avoid this
;; ...
;; [panic] out of memory - cannot allocate heap segment - execution terminated
;; Case 2: 100% cpu with no apparent progress
;; Output with -:g
;; ...
;; [GC] 2 finalized item(s) still pending
;; [GC] 2680 finalizer value(s) marked
;; [GC] level 1 gcs(minor) 379 gcs(major) 22
;; [GC] stack 0xbfef7880 0xbff36a00 0xbff37880
;; [GC] from 0x773d9008 0xb731f744 0xb73d9000 0x3ff4673c
;; [GC] to 0x09123008 0x09123008 0x49123000
;; [GC] 0 locatives (from 32)
;; 681
;; [GC] 2 finalized item(s) still pending
;; [GC] 2681 finalizer value(s) marked
;; [GC] level 1 gcs(minor) 0 gcs(major) 23
;; [GC] stack 0xbfef7880 0xbff36a00 0xbff37880
;; [GC] from 0x09123008 0x490cb1d8 0x49123000 0x3ffa81d0
;; [GC] to 0x773d9008 0x773d9008 0xb73d9000
;; [GC] 0 locatives (from 32)
;; <- stuck here with 100% cpu
;; Case 3: 100% at the end
;; making 1
;; making 2
;; ...
;; ...
;; gc'ing 103
;; gc'ing 102
;; gc'ing 101
;; Caught an exception#<condition: (exn type)>
;; done
;; <- stuck here with 100% cpu
Changes and comments
[2012-06-14 10:10:06 UTC] felix changed status from new to assigned
[2012-06-14 10:10:06 UTC] felix set owner to felix
[2012-06-15 14:47:38 UTC] felix wrote:
The attached patch adds catching any errors during finalizer execution, but there still seems to be a problem - running the test sometimes crashes (seems to depend on memory layout or something similar).
[2012-06-16 14:00:03 UTC] felix attached 0001-Catch-exceptions-in-finalizers-and-added-tests.patch (description=better variant)
[2012-06-16 14:00:52 UTC] felix changed milestone from 4.9.0 to 4.8.0
[2012-06-16 14:01:03 UTC] felix changed component from unknown to core libraries
[2012-06-30 13:37:57 UTC] sjamaan wrote:
Hopefully this is the final fix for this problem:
http://lists.nongnu.org/archive/html/chicken-hackers/2012-06/msg00100.html
[2012-07-04 22:11:59 UTC] sjamaan changed status from assigned to closed
[2012-07-04 22:11:59 UTC] sjamaan set resolution to fixed
[2012-07-04 22:11:59 UTC] sjamaan wrote:
This was applied, so I'm closing the ticket
[2012-09-24 21:47:48 UTC] felix changed milestone from 4.8.0 to 4.9.0
[2012-09-24 21:47:48 UTC] felix wrote:
Milestone 4.8.0 deleted