Foreman/puppet agent fails from time to ttime

I inherited a Foreman setup with puppet master. The problem recently is
that puppet agents stops running from time to time with errors like:

Error: Could not retrieve catalog from remote server: end of file reached
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

I checked the logs on remote Foreman/Puppet master server, the log in
/var/log/messages shows that the catalog was compiled without issues:

Jul 28 15:38:24 foreman puppet-master[16414]: Compiled catalog for
puppetagent01.example.com in environment production in 35.06 seconds

If I run 'puppet agent --test' on puppetagent01 a few times, then the
problem may disappear at any time and runs normally.

This issue really drives me nuts and I just pulls my hair, any one can shed
a light on what are the possible areas failed, and how to debug it if
possible? Many thanks.