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);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions