Skip to content

Learning transport throws exceptions when running multiple endpoint instances #7324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/NServiceBus.Core/Transports/Learning/AsyncFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ public static async Task<bool> Move(string sourcePath, string targetPath, Cancel

if (!IsFileLocked(targetPath))
{
break;
return true;
}

await Task.Delay(100, cancellationToken).ConfigureAwait(false);

count++;
}

return true;
return false;
}

static bool IsFileLocked(string filePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ public DirectoryBasedTransaction(string basePath, string pendingDirName, string

public string FileToProcess { get; private set; }

public Task<bool> BeginTransaction(string incomingFilePath, CancellationToken cancellationToken = default)
public async Task<bool> BeginTransaction(string incomingFilePath, CancellationToken cancellationToken = default)
{
Directory.CreateDirectory(transactionDir);
FileToProcess = Path.Combine(transactionDir, Path.GetFileName(incomingFilePath));

return AsyncFile.Move(incomingFilePath, FileToProcess, cancellationToken);
var succeeded = await AsyncFile.Move(incomingFilePath, FileToProcess, cancellationToken).ConfigureAwait(false);
if (succeeded)
{
return true;
}

Directory.Delete(transactionDir, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rollback already does a delete. Is the rollback not consistently called and we have to do extra cleanup here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Rollback method is only called when BeginTransaction returns true

return false;

}

public async Task Commit(CancellationToken cancellationToken = default)
Expand Down