laravel-idempotency icon indicating copy to clipboard operation
laravel-idempotency copied to clipboard

Serialization of Closure Not Allowed

Open zlanich opened this issue 6 years ago • 6 comments

After upgrading to Laravel 5.7, I'm getting a Serialization of Closure not allowed on a ton of my requests. The error went away when I disabled this middleware. Help!

zlanich avatar Oct 14 '18 00:10 zlanich

More details, it only seems to occur in my Redis Store. Here's a full stack trace: https://sentry.io/share/issue/9b7f938e4bb6410f9ae6d5c2bbddae46/

zlanich avatar Oct 14 '18 02:10 zlanich

Following the issue, did you resolve the issue? I've tried it on Laravel 5.7 and Laravel 5.8 with no problems. Seems like you have something attached to the response object that cannot be serialized.

javidalpe avatar Mar 14 '19 15:03 javidalpe

@javidalpe I haven't been able to resolve this yet because it's a really intermittent issue that occurs in the production environment with a decent volume of requests, so I haven't been able to reproduce it and I can't leave the prod env broken. I'm not sure of the best way to go about debugging it yet.

zlanich avatar Mar 16 '19 05:03 zlanich

$response = $next($request);
$response->header(self::IDEMPOTENCY_HEADER, $requestId);
Cache::put($requestId, $response, self::EXPIRATION_IN_MINUTES);

In my case I have found that if $response is of type Illuminate\Http\Response, Cache is able to serialise and save it. However if $response is of type Illuminate\Http\JsonResponse I get the Serialization of closure is not allowed error message.

I don't any work around for it. any suggestions?

karunkshrestha avatar Dec 05 '19 15:12 karunkshrestha

For any one still having the issue, this works fine for me

        Cache::put($requestId, [
            "response" => $response->getContent(),
            "path" => $request->path(),
            "status" => $response->status()
        ], now()->addMinutes(self::EXPIRATION_IN_MINUTES));

simioluwatomi avatar Sep 10 '20 14:09 simioluwatomi

Screenshot 2022-04-27 at 11 13 52 AM this issue still persist. It kinda conflicting with my request validation. @javidalpe

AbdullahiAbdulkabir avatar Apr 27 '22 10:04 AbdullahiAbdulkabir