Profile cover photo
Profile photo
Len Holgate
About
Posts

Post has attachment
New member of the family
PhotoPhotoPhotoPhotoPhoto
06/10/2018
11 Photos - View album
Add a comment...

Post has attachment
Photo
Add a comment...

Post has attachment

Post has attachment

Post has attachment
Practical Testing: 35 - Heap corruption

Previously on "Practical Testing"... I've just fixed a new bug in the timer queue and in doing so I updated the code used in the blog posts to the latest version that ships with The Server Framework. This code included two fixes that had been fixed some time ago and which I hadn't documented here. They also lacked unit tests... In this episode I find and fix the first of these issues by writing a unit test that triggers the issue.

This bug is another edge case that isn't used that often by most of the code that uses the timer queue. The queue supports timers that can be set and reset a number of times via an interface that allows you to create a timer, set/cancel it and then destroy the timer. A less used interface allows you to create 'fire and forget' timers that can only be set once and that clean themselves up. Hardly any code that I write uses this interface but it's there for backwards compatibility and the code required to support it is limited to the call that sets the initial timer, as the cleanup is done by code that's shared with timers that are deleted during their own timeout processing.

This bug also only affects the Timer Wheel implementation which has a considerably smaller set of users and a considerably narrower use case. There's test coverage for "one shot" timers but only for timers that are processed whilst the timer queue's internal lock is held. There is no test for a "one shot" timer for queues that dispatch without holding a lock. The code for lock-free dispatch is significantly different to the code for dispatch whilst holding a lock and that's where the bug is.

The bug was originally found because it causes heap corruption due to a double delete. The first thing I'll do is add a test for lock-free timer dispatch of "one shot" timers. This clearly demonstrates the bug when run in release mode on Windows 10 as the heap alerts us to the problem.

Continue reading
Add a comment...

Post has attachment
We drove over to Munich and back to visit Emma and family. The last minute purchase of DVD players was a good idea...
Add a comment...

Post has attachment
Easter in Guernsey with DadDad and DoDo.
Add a comment...

Post has shared content
We all had hectic, noisy fun at New Year.
Add a comment...

Post has shared content

Post has attachment
Photo
Add a comment...
Wait while more posts are being loaded