Skip to content
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

Throw exception when PublishAsync #80

Closed
trumhemcut opened this issue Jan 22, 2018 · 4 comments

Comments

@trumhemcut
Copy link

commented Jan 22, 2018

My config at Startup.cs

            services.AddDbContext<TradeBotDbContext>(ServiceLifetime.Transient);

            services.AddCap(cap =>
            {
                cap.UseEntityFramework<TradeBotDbContext>();
                cap.UseRabbitMQ(Configuration["CAP:RabbitMQ:HostName"]);
            });
            services.AddTransient<ICapPublisher, CapPublisher>();
            services.AddMvc();
            services.AddSingleton<IHostedService, TradeBotService>();

Then, Just simply call this in the Service

await CapPublisher.PublishAsync("test", new { Message = "Hello World" });

And it throws the exception The transaction operation cannot be performed because there are pending requests working on this transaction. sometimes.

It throws here:

        private void ClosedCap()
        {
            if (IsCapOpenedTrans)
            {
                DbTransaction.Commit(); // THROW WHEN CALLING HERE
                DbTransaction.Dispose();
            }
            if (IsCapOpenedConn)
                DbConnection.Dispose();
        }

I'm using SQL Server on Linux as the storage

UPDATED:
Trying with the Postgres and it says:
A command is already in progress: INSERT INTO Cap.[Published] ([Name],[Content],[Retries],[Added],[ExpiresAt],[StatusName])VALUES(@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName)

@yang-xiaodong

This comment has been minimized.

Copy link
Member

commented Jan 23, 2018

How do you call this PublishAsync method?

Are you using a loop call in an action like:

public async Task<IActionResult> TestSent()
{
    for(int i=0; i<10000; i++ ){
        await CapPublisher.PublishAsync("test", new { Message = "Hello World" });
    }
}

Or are you calling repeatedly with the http api test tool like wrk ?

wrk -c 20 -t 4 -d 20 http://localhost:5000/api/testsend

[Route("~/api/testsend")]
public async Task<IActionResult> TestSent()
{
    await CapPublisher.PublishAsync("test", new { Message = "Hello World" });
}
@trumhemcut

This comment has been minimized.

Copy link
Author

commented Jan 23, 2018

I'm using the loop as the first block you described. This is my code

while (true)
{
    try
    {
        if (CapPublisher != null)
            await CapPublisher.PublishAsync("test", new { Message = "Hello World" });
        // more code here ...
        await Task.Delay(1300);
    }
    catch (Exception ex)
    {
        // ...
    }
}

I'm using IHostedService to use kestrel host the background service.

@yang-xiaodong yang-xiaodong added the bug label Jan 24, 2018

yang-xiaodong added a commit that referenced this issue Jan 24, 2018

@yang-xiaodong yang-xiaodong added the fixed label Jan 24, 2018

@yang-xiaodong

This comment has been minimized.

Copy link
Member

commented Jan 24, 2018

Hi, @trumhemcut
I have fixed this problem and released the version of v2.1.3
Thanks for your report.

@trumhemcut

This comment has been minimized.

Copy link
Author

commented Jan 26, 2018

that looks good, thanks @yuleyule66 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.