question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Asynchronously processing GetObjectAsync stream

See original GitHub issue

Feature request:

GetObjectAsync takes a synchronous stream processor. It defeats the point of the call being asynchronous, unless I’m misunderstanding something (is the stream buffered in memory already?)

Task GetObjectAsync(string bucketName, string objectName, Action<Stream> callback, ServerSideEncryption sse = null, CancellationToken cancellationToken = default(CancellationToken))

It would be great to see an overload like:

Task GetObjectAsync(string bucketName, string objectName, Func<Stream, Task> callback, ServerSideEncryption sse = null, CancellationToken cancellationToken = default(CancellationToken))

Notice how callback is changed Action<Stream> callback -> Func<Stream, Task> callback.

For the time being, I came up with a workaround using TaskCompletionSource, although I cannot test if it is truly asynchronous or blocking.

                var completion = new TaskCompletionSource<object>();

                await _client.GetObjectAsync(_options.BucketName, name, async s =>
                {
                    await s.CopyToAsync(file.Stream, cancellationToken);

                    completion.TrySetResult(null);
                }, null, cancellationToken);

                await completion.Task;

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Biztactix-Ryancommented, Sep 1, 2022

@harshavardhana @edemartel @cosminvlad There’s more than one of us sitting here wondering if this is going to get sorted.

Many users will be using this in asp.net of some type, I can only expect that nearly all of them would want to pass data from Minio directly to the user, It would be very rare that we’d need to cache such data. so loading it into a memory stream then writing it to the response stream is double handling and depending on the size of the return may even overrun server memory.

Now if you have already covered this scenario and have an answer, it’d be great to know as I’ve just checked the docs again and it’s still using the callback. If we can’t get such a simple thing sorted, We’ll just move on and it’ll be with another platform.

3reactions
cristipufucommented, Oct 27, 2020

Same here:

Unsuccessful response from server without XML error: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.: Minio.Exceptions.InternalClientException: Minio API responded with message=Unsuccessful response from server without XML error: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.
   at void Minio.MinioClient.ParseError(IRestResponse response) in /q/.q/sources/minio-dotnet/Minio/MinioClient.cs:line 450
   at void Minio.MinioClient.HandleIfErrorResponse(IRestResponse response, IEnumerable<ApiResponseErrorHandlingDelegate> handlers, DateTime startTime) in /q/.q/sources/minio-dotnet/Minio/MinioClient.cs:line 505
   at async Task<IRestResponse> Minio.MinioClient.ExecuteTaskAsync(IEnumerable<ApiResponseErrorHandlingDelegate> errorHandlers, IRestRequest request, CancellationToken cancellationToken) in /q/.q/sources/minio-dotnet/Minio/MinioClient.cs:line 352
   at async Task Minio.MinioClient.GetObjectAsync(string bucketName, string objectName, Action<Stream> cb, CancellationToken cancellationToken) in /q/.q/sources/minio-dotnet/Minio/ApiEndpoints/ObjectOperations.cs:line 56
   at async Task UiPath.Storage.Minio.MinioStorageClient.ReadObjectAsync(StorageLocation location, Stream stream, CancellationToken cancellationToken)

As a workaround we have to enable AllowSynchronousIO in our web app:

services.Configure<IISServerOptions>(options =>
{
    options.AllowSynchronousIO = true;
});

This limitation comes from the underlying RestSharp client itself, I think it’s time to get rid of it and use Microsoft’s HttpClient

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a read stream of a AWS S3 object in a async ...
Late to the party, but I believe you simply wanted to do: var readableStream = await s3.getObject({ Bucket: bucket, Key: filename }).
Read more >
Asynchronous programming - AWS SDK for Java 2.x
For streaming operations, you must provide an AsyncRequestBody to provide the content incrementally, or an AsyncResponseTransformer to receive and process the ...
Read more >
How to create a read stream of a AWS S3 object in a async ...
How to create a read stream of a AWS S3 object in a async function? If I try ``` exports.handler = async (event)...
Read more >
How to Create a Read Stream of an AWS S3 Object in ...
In this blog post, we'll guide you through the process of creating a read stream of an AWS S3 object in an async...
Read more >
Using streams when getting objects from S3
We should change how we process the getObject requests in our Node.js AWS ... asyncIterator method, so the streams are also async iterables....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found