fix race condition with StringMatcher

See #389 for background.

@osa1 please review