Ticket #5088 (closed bug: invalid)

Opened 2 years ago

Last modified 2 years ago

TextEncoding iconv instances are shared between threads

Reported by: batterseapower Owned by:
Priority: normal Milestone:
Component: libraries/base Version: 7.0.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

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
  1. (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

Change History

Changed 2 years ago by batterseapower

Sorry, this is wrong: this issue only effects the output of running mkText{Decoder,Encoder} so I'm not sure its as important as I thought. Probably still worth documenting though.

Changed 2 years ago by batterseapower

  • status changed from new to closed
  • resolution set to invalid

I documented the invariants on these things in 54a0b49. Current usage is safe because Handle is protected by a MVar, and in my (uncommitted) CString code the decoder/encoder only exist for the lifetime of a stack frame.

Note: See TracTickets for help on using tickets.