RT 5.0.3 mail error: Can't call method "Name" on an undefined value

We migrated from 4.4.0 to 5.0.3 and frequently we’re seeing the error below.

(temporary failure. Command output: /usr/local/rt/bin/rt-mailgate: temp file is ‘/tmp/DPveebPakk/iNJ5Apu0SD’ /usr/local/rt/bin/rt-mailgate: connecting to https:///rt/REST/1.0/NoAuth/mail-gateway Can’t call method “Name” on an undefined value at /usr/local/rt-5.0.3/sbin/…/lib/RT/Interface/Web.pm line 1411.

We are using Postfix and Apache 2.4.

Postfix will retry to deliver and the messages end up in RT as new tickets for each redelivery attempt. Restarting Apache and flushing the mail queue will temporarily resolve the problem.

httpd.conf Location directive
<Location /rt/REST/1.0/NoAuth/mail-gateway>
Require local

RT log snippet: [debug]: sesion{“CurrentUser”} somehow undefined

We’ve been able to modify Web.pm so that the tickets get created and the mail isn’t stuck in the queue. Anyone have any ideas what might be the issue?