Skip to content

TextEncoding iconv instances are shared between threads

The icon_t pointers returned from iconv_open should only be while processing a single text stream, because in general they may contain some state about the text being processed.

However, we currently don't take any measures to prevent this from happening, as GHC.IO.Encoding.Iconv.mkTextEncoding shares one pointer amongst all use sites of that TextEncoding in future -- even if those uses occur on different threads!

This could lead to arbitrarily strange heisenbugs depending on the iconv implementation.

Either we should:

  1. Make it clear that the user should recreate a TextEncoding anew for every use site
  2. (Better), elaborate the TextEncoding interface so that we can call iconv_open/iconv_close at the start and end of processing a particular text block, and ensure that the token doesn't escape so it can be accessed from multiple threads simultaneously
Trac metadata
Trac field Value
Version 7.0.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information