tombstone icon indicating copy to clipboard operation
tombstone copied to clipboard

Unable to determine stream size. Did you forget to close or flush the stream?

Open pandian1989 opened this issue 9 months ago • 9 comments

I am getting Unable to determine stream size. Did you forget to close or flush the stream? when i am use S3 as storage with streamwrapper. Can you suggest me how to resolve this issue.

pandian1989 avatar Jan 31 '25 05:01 pandian1989

Writing data to S3 seems to have specific requirements. The logging implementation is very similar to what Monolog is doing and I believe Monolog doesn't support S3 out-of-the-box.

I've found this article on StackOverflow, describing that you need to do some client initialization first. Maybe that helps.

scheb avatar Jan 31 '25 08:01 scheb

Yeah. Same way i did client initialization like this

private function configureS3LogStorage(): void
    {
        $client = new S3Client([
            'region' => 'us-west-2',
            "version" => '2006-03-01',
            "credentials"=> [
                "key" => 'some key',
                "secret" => 'some secret'
            ]
        ]);
        $client->registerStreamWrapper();
    }

Before build graveyard, i call this function to initialize client with stream wrapper of s3 storage.

pandian1989 avatar Jan 31 '25 08:01 pandian1989

Did you write your own log handler or are you using the standard one that comes with the library? If you're using the battery standard one I'd suggest you try it with a custom one specifically for the S3 use case.

scheb avatar Jan 31 '25 08:01 scheb

I'm using AnalyzerLogHandler which uses the inbuild StreamHandler . So I just register client and before build graveyard and it was working but concern is that whenever use concurrency of calls it throws.

Unable to determine stream size. Did you forget to close or flush the stream?

pandian1989 avatar Jan 31 '25 08:01 pandian1989

I did understand this, but I also don't have an idea where this is coming from. My guess is that something in the way the standard StreamHandler workes is incompatible with the S3 protocol. Therefore my suggestion, to implement a custom handler specifically for S3.

scheb avatar Jan 31 '25 08:01 scheb

Can i have any sample contract to write custom handler and it would be helpful for me.

pandian1989 avatar Jan 31 '25 09:01 pandian1989

Have a look at these classes: https://github.com/scheb/tombstone/tree/1.x/src/logger/Handler

scheb avatar Jan 31 '25 10:01 scheb

Is it possible to add fflush to flush file output buffer in stream handler because since flush method declared but not implemented in stream handler.

pandian1989 avatar Feb 05 '25 05:02 pandian1989

Sorry, I don't understand what you mean.

I wouldn't want to touch the StreamHandler so much as this would potentially break other people's implementations. My recommendation is to implement a custom handler that fits your needs.

scheb avatar Feb 05 '25 08:02 scheb