fix(lambdaweb): refuse a function name another region already has (#6409)

* fix(lambdaweb): refuse a function name another region already has

AWS keeps web function names unique across the regions of an account.
CreateWebFunction with a name another region has is 409
ConflictException "A function named <name> already exists in the
account. Function names must be unique across all regions in an
account.", at the same point as the same-region conflict.

* fix(lambdaweb): key the function name lock by account

* perf(lambdaweb): find a name in other regions without copying every key
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-24 08:37:19 -04:00
1 parent 3b4589645b
commit 4e0bf080ed
3 files changed
+32 -9

No files matched your search

@@ -335,19 +335,29 @@ public class LambdaWebService implements Resettable {
}
}
/** Stores a new function under its lock, refusing a name the region already has. */
/**
* Stores a new function under its lock, refusing a name the account already has in any region.
* Creates of one name in every region of the account share a lock, so two regions cannot both take it.
*/
private WebFunction storeNewFunction(String region, String functionName, Map<String, String> tags,
Consumer<WebFunction> populate) {
String accountId = regionResolver.getAccountId();
synchronized (lockFor(region, functionName)) {
if (functions.get(key(region, functionName)).isPresent()) {
throw new AwsException("ConflictException",
"The function " + functionArn(region, accountId, functionName) + " already exists.", 409);
synchronized (locks.computeIfAbsent(accountId + "/" + functionName, k -> new Object())) {
synchronized (lockFor(region, functionName)) {
if (functions.get(key(region, functionName)).isPresent()) {
throw new AwsException("ConflictException",
"The function " + functionArn(region, accountId, functionName) + " already exists.", 409);
}
if (!functions.scan(k -> k.endsWith("/" + functionName)).isEmpty()) {
throw new AwsException("ConflictException", "A function named " + functionName
+ " already exists in the account. Function names must be unique across all regions"
+ " in an account.", 409);
}
WebFunction fn = newFunction(region, accountId, functionName, tags == null ? Map.of() : tags);
populate.accept(fn);
functions.put(key(region, functionName), fn);
return copy(fn, WebFunction.class);
}
WebFunction fn = newFunction(region, accountId, functionName, tags == null ? Map.of() : tags);
populate.accept(fn);
functions.put(key(region, functionName), fn);
return copy(fn, WebFunction.class);
}
}