Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Running several VPC peering operations asynchronously

Hi,

Isn't the parallel peering operation from the same source supported in the GCP API?

When running several VPC peering creation or deletion operations asynchronously on a single source, using the Java Client, the VPC the operation fails with the "There is a peering operation in progress on the local or peer network. Try again later" error.

3 2 157
2 REPLIES 2

Hi @roy-michael ,

GCP API doesn't support parallel peering operations from the same source. VPC peering operations rely on the completion of the previous one, and allowing multiple operations to run concurrently could lead to conflicts.


@roy-michael wrote:

"There is a peering operation in progress on the local or peer network. Try again later"


This is a clear indication of this limitation. It suggests that the API is designed to handle one peering operation at a time, and attempting to run multiple operations simultaneously will result in a failure.

You can try implementing a sequential approach to your VPC peering creation or deletion operations. This can be done by waiting for the completion of each operation before initiating the next one. You can use the operations.wait() method provided by the Java client library to achieve this. Below is the sample code snippet showing how you can implement the sequential approach:

// Initialize your VPC Peering object
VpcPeeringsServiceClient vpcPeeringsServiceClient = VpcPeeringsServiceClient.create();

// Create a VPC peering operation
VpcPeeringsOperation operation = vpcPeeringsServiceClient.createVpcPeering(projectId, region, vpcPeering);

// Wait for the operation to complete
operation.waitUntilDone();

// Check if the operation was successful
if (operation.getDone() && operation.getResult() != null) {
// Handle the successful response
} else {
// Handle the error response
}

You can try repeating this process for each VPC peering operation. Let me know if this works.

Hi @Marvin_Lucero and thank you for your replay.

The suggested solution would not work well when peering simultaneously from different contexts on the same vpc, it can cause starvation for one or more of the parties involved. That is why it is more natural for the server/backend to handle such situation and not the client.

For some reason i cannot find any reference to the VpcPeeringsServiceClient. Is it part of v1 API?