Skip to content

SimpleFunctionRegistry.wrappedFunctionDefinitions is not thread-safe #1423

Description

@xcy2023

Describe the bug

branch: 4.3.x

SimpleFunctionRegistry.wrappedFunctionDefinitions is not thread-safe. And the testBoundedFunctionCache testcase in BeanFactoryAwareFunctionRegistryTests.java should test on wrappedFunctionDefinitions.size() but not catalog.size().

Sample

// BeanFactoryAwareFunctionRegistryTests.java
@Test
public void testBoundedFunctionCache() throws Exception {
	FunctionCatalog catalog = this.configureCatalog(CompositionWithNullReturnInBetween.class);
	Field wrappedFunctionDefinitionsCacheSizeField = ReflectionUtils
			.findField(catalog.getClass(), "wrappedFunctionDefinitionsCacheSize");
	wrappedFunctionDefinitionsCacheSizeField.setAccessible(true);
	wrappedFunctionDefinitionsCacheSizeField.set(catalog, 10);
	Field wrappedFunctionDefinitionsField = ReflectionUtils
		.findField(catalog.getClass(), "wrappedFunctionDefinitions");
	wrappedFunctionDefinitionsField.setAccessible(true);
	int threadCount = 20;
	CountDownLatch latch = new CountDownLatch(threadCount);
	for (int i = 0; i < threadCount; i++) {
		new Thread(() -> {
			catalog.lookup("echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2");
			catalog.lookup("echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1");
			latch.countDown();
		}).start();
	}
	latch.await();
	assertThat(((Map<?, ?>) (wrappedFunctionDefinitionsField.get(catalog))).size()).isEqualTo(10);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions