PHP / Magento Dev Blog

  • Home

Magento 2 checkout freezes on shipping step – external carrier API timeout

by Henryk Tews / Thursday, 10 September 2026 / Published in Magento / Adobe Commerce

Checkout was freezing on the shipping selection step – the spinner kept spinning indefinitely. Customers could not proceed. The problem affected 100% of users on all browsers. Diagnosis time: 2 hours, fix time: 20 minutes.

Symptoms

  • The “Shipping” step in checkout never finishes loading
  • In DevTools Network: GET /rest/V1/carts/mine/shipping-methods returns 500
  • In var/log/exception.log: PHP error in custom carrier module
  • Problem started after deploying a new shipping module

Diagnosis

curl -s -H "Authorization: Bearer TOKEN" \
  https://shop.com/rest/V1/carts/mine/shipping-methods \
  | python3 -m json.tool

tail -50 var/log/exception.log | grep -A 10 "shipping"

# Disable carriers one by one to isolate the problem
bin/magento config:set carriers/custom_carrier/active 0
bin/magento cache:flush

Cause

The new custom carrier’s collectRates() method was calling an external courier API without a timeout. The API was unavailable – PHP waited 30 seconds until nginx terminated the connection. The error was not being logged because the exception was thrown after the nginx timeout.

Solution

<?php
class CustomCarrier extends \Magento\Shipping\Model\Carrier\AbstractCarrier
    implements \Magento\Shipping\Model\Carrier\CarrierInterface
{
    protected $_code = 'custom_carrier';

    public function collectRates(
        \Magento\Quote\Model\Quote\Address\RateRequest $request
    ): ?\Magento\Shipping\Model\Rate\Result {
        if (!$this->getConfigFlag('active')) return null;

        $result = $this->_rateResultFactory->create();

        try {
            // Always set timeout for external APIs
            $this->_httpClient->setConfig(['timeout' => 5]);
            $rates = $this->fetchRatesFromApi($request);

            foreach ($rates as $rate) {
                $method = $this->_rateMethodFactory->create();
                $method->setCarrier($this->_code);
                $method->setMethod($rate['code']);
                $method->setMethodTitle($rate['name']);
                $method->setPrice($rate['price']);
                $result->append($method);
            }
        } catch (\Exception $e) {
            // Log error but do not throw - checkout must keep working
            $this->_logger->error('Custom carrier API error', [
                'exception' => $e->getMessage(),
            ]);

            // Optional: show fallback rate instead of nothing
            if ($this->getConfigData('show_fallback')) {
                $method = $this->_rateMethodFactory->create();
                $method->setCarrier($this->_code);
                $method->setMethod('fallback');
                $method->setMethodTitle('Standard delivery');
                $method->setPrice((float)$this->getConfigData('fallback_price'));
                $result->append($method);
            }
        }

        return $result;
    }
}

Takeaways

The collectRates() method must be resilient to external API failures. A timeout is mandatory – without it one unavailable carrier blocks the entire checkout. Log errors but do not throw exceptions – the customer should not see a technical error, just a missing shipping option. Consider a fallback rate for critical carriers.

About Henryk Tews

What you can read next

Strategy pattern in PHP – and how Magento 2 uses it in pricing
Xdebug – configuration, PHPStorm, debugging Magento plugins

© 2026 Created by

TOP
Zarządzaj zgodą
Aby zapewnić jak najlepsze wrażenia, korzystamy z technologii, takich jak pliki cookie, do przechowywania i/lub uzyskiwania dostępu do informacji o urządzeniu. Zgoda na te technologie pozwoli nam przetwarzać dane, takie jak zachowanie podczas przeglądania lub unikalne identyfikatory na tej stronie. Brak wyrażenia zgody lub wycofanie zgody może niekorzystnie wpłynąć na niektóre cechy i funkcje.
Funkcjonalne Always active
Przechowywanie lub dostęp do danych technicznych jest ściśle konieczny do uzasadnionego celu umożliwienia korzystania z konkretnej usługi wyraźnie żądanej przez subskrybenta lub użytkownika, lub wyłącznie w celu przeprowadzenia transmisji komunikatu przez sieć łączności elektronicznej.
Preferencje
Przechowywanie lub dostęp techniczny jest niezbędny do uzasadnionego celu przechowywania preferencji, o które nie prosi subskrybent lub użytkownik.
Statystyka
Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do celów statystycznych. Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do anonimowych celów statystycznych. Bez wezwania do sądu, dobrowolnego podporządkowania się dostawcy usług internetowych lub dodatkowych zapisów od strony trzeciej, informacje przechowywane lub pobierane wyłącznie w tym celu zwykle nie mogą być wykorzystywane do identyfikacji użytkownika.
Marketing
Przechowywanie lub dostęp techniczny jest wymagany do tworzenia profili użytkowników w celu wysyłania reklam lub śledzenia użytkownika na stronie internetowej lub na kilku stronach internetowych w podobnych celach marketingowych.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Zobacz preferencje
  • {title}
  • {title}
  • {title}