Skip to content

NET8: DefaultObjectPool<T>.Get() method returns null under multi-threads, seems not thread-safe with NET8 and throws exception, while no problem with NET7 #52873

@xiaoyuvax

Description

@xiaoyuvax

Description

In case of multi-threads, ObjectPool.Get() returns null, seems not thread-safe under NET8 (8.0.0) and throws exception, but not under NET7.

Reproduction Steps

Checkout below demo to reproduce, watch for debugger break in the logger codes:

Symptom:

ObjectPool.Get() in the log object's WriteInternal() method, which uses a DefaultObjectPool, throws exception.
While the ObjectPoolCase1 and ObjectPoolCase2 in Main() seems not causing this problem, nor eitherway under NET7.

https://github.com/xiaoyuvax/ObjectPoolReuseCaseDemo

Expected behavior

DefaultObjectPool.Get() should be thread-safe, and always return an object instead of null.

Actual behavior

DefaultObjectPool.Get() returns null randomly.

Regression?

No response

Known Workarounds

Check if returns null and use new keyword to create new instance

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions