Skip to content

object.extend(mod) is occasionally nondeterministically applied #3925

@halostatue

Description

@halostatue
NoMethodError: undefined method `load_preferred_extension' for an instance of MIME::Types
    lib/mime/type/columnar.rb:55:in `preferred_extension'
    lib/mime/type.rb:221:in `__extension_priority_compare'
    lib/mime/types.rb:156:in `block in type_for'
    <internal:core> core/array.rb:1588:in `isort_block!'
    <internal:core> core/array.rb:1498:in `mergesort_block!'
    <internal:core> core/array.rb:1406:in `sort_fallback'
    <internal:core> core/array.rb:1707:in `sort'
    <internal:core> core/array.rb:1707:in `sort!'
    <internal:core> core/enumerable.rb:470:in `sort'
    lib/mime/types.rb:151:in `type_for'
    lib/mime/types/registry.rb:36:in `type_for'
    test/test_mime_types.rb:16:in `block in mime_types'
    <internal:core> core/kernel.rb:520:in `tap'
    test/test_mime_types.rb:8:in `mime_types'
    test/test_mime_types.rb:37:in `test_0004_is countable with an enumerator'

The line numbers against mime-types/ruby-mime-types main differ from the exact report here (as I have been investigating this for a couple of days), but are regularly but inconsistently reproducible with rake test using truffleruby 24.2.1, like ruby 3.3.7, Oracle GraalVM Native [arm64-darwin20]. Sticking with a given seed (SEED=6845 rake test) does not change the behaviour to deterministic, but roughly ⅓ to ½ of the test runs fail.

I have tried several different resolutions: removing metaprogramming, putting the container.extend(MIME::Types::Columnar).load_base_data(path) call inside of a Mutex.new.synchronize { … } block, etc. None have worked. There is one more change that I can make, but I wish to avoid that, because it will take a couple of weeks to resolve for a single interpreter misbehaving.

When a test is run by itself, this rarely happens. But it happens fairly often when the test suite as a whole is run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions