skip to Main Content

I’ve upgraded my Symfony app from 6.2 to 6.3.
Locally everything work perfect, but I have a problem on staging environment.
When I’m trying to sign in via API (or get some resources) I’m reciveing 503 First Byte Timeout from Varnish Cache Server.
In Kubernetes logs everything is fine (Response status code is 204 and headers are present).

I’ve changed some Normalizer classes to remove deprecations, ex. UserNormalizer

Version before upgrade:

<?php

declare(strict_types=1);

namespace AppApiUserSerializer;

use AppEntityUser;
use AppRepositoryCategoryRepository;
use SymfonyComponentSerializerNormalizerCacheableSupportsMethodInterface;
use SymfonyComponentSerializerNormalizerNormalizerInterface;

class UserNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
{
    public function __construct(
        private readonly NormalizerInterface $itemNormalizer,
        private readonly CategoryRepository $categoryRepository,
    ) {
    }

    /** @param User $object */
    public function normalize($object, $format = null, array $context = []): array|string
    {
        $object->categoryIds = $this->categoryRepository->findIdsWithJobsByUser($object);

        return $this->itemNormalizer->normalize($object, $format, $context);
    }

    public function supportsNormalization($data, $format = null, array $context = []): bool
    {
        return $data instanceof User;
    }

    public function hasCacheableSupportsMethod(): bool
    {
        return true;
    }
}

and after upgrade

<?php

declare(strict_types=1);

namespace AppApiUserSerializer;

use AppEntityUser;
use AppRepositoryCategoryRepository;
use SymfonyComponentSerializerNormalizerNormalizerInterface;

final readonly class UserNormalizer implements NormalizerInterface
{
    public function __construct(
        private NormalizerInterface $itemNormalizer,
        private CategoryRepository $categoryRepository,
    ) {
    }

    /** @param User $object */
    public function normalize($object, $format = null, array $context = []): array|string
    {
        $object->categoryIds = $this->categoryRepository->findIdsWithJobsByUser($object);

        return $this->itemNormalizer->normalize($object, $format, $context);
    }

    public function supportsNormalization($data, $format = null, array $context = []): bool
    {
        return $data instanceof User;
    }

    public function getSupportedTypes(?string $format): array
    {
        return [
            '*' => false,
            User::class => true,
        ];
    }
}

I’ve removed implementation of CacheableSupportsMethodInterface (with method hasCacheableSupportsMethod()) and replaced it with getSupportedTypes() according to documentation and built-in normalizer.

My app is running on Google Kubernetes Engine (GCP) and is delivered via Fastly.

Does anyone faced same issue?

PS. Some resources are correct (ex. Static Pages, which are also cached and has simillar getSupportedTypes() implementation).

2

Answers


  1. Chosen as BEST ANSWER

    Solved.

    The problem was pcntl extension which was obligatory for Messenger with version 6.3.5.

    After update Messenger to 6.3.7 I removed pcntl extension from my docker image and all problems with cache disapeared.


  2. Fastly allows you to configure the ‘time to first byte’ timeout…

    The default is 15s, which (to me) sounds like it should be plenty. So I’d also suggest investigating any network connectivity issues that might be slowing down responses.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search