Fetchmail & Apache error 500

Hello there!
After being digging for a while, I’ve being missing something but can’t figure out what. When I try to run fetchmail with its respective fetchmailrc file I get “HTTP request failed: 500 Internal Server Error.”
Then I check the Apache error logs and I get:
[fcgid:warn] [pid 10894] [client] mod_fcgid: read data timeout in 40 seconds
[core:error] [pid 10894] [client] End of script output before headers: rt-server.fcgi
While the access_log shows: - - [23/Jun/2020:16:57:28 +0200] “POST /REST/1.0/NoAuth/mail-gateway HTTP/1.1” 500 527 “-” “rt-mailgate/4.4.4 libwww-perl/6.05”
::1 - - [23/Jun/2020:16:58:47 +0200] “POST /REST/1.0/NoAuth/mail-gateway HTTP/1.1” 500 527 “-” “rt-mailgate/4.4.4 libwww-perl/6.05”

Could please anyone tell if I missed something that I should set on Apache to solve this error?

Thank you very much. Any help would be appreciated.

You can try increasing the timeout value for fcgid, the FcgidIOTimeout config value controls how long fcgid will wait for data to come back. The default is only 40 seconds, so this may be the limit you are running into now.

You can also set the FcgidBusyTimeout, which controls the maximum time limit for request handling.

A couple of questions:

Does the web interface for your RT work?

Does this error only occur for some emails going into RT or all emails? Maybe emails with attachments?

Thanks for your quick answer. Unfortunately, after having set both values for fcgid the issue persists.
And yes, web UI is working.
Finally, this error occurs with just a simple mail to check and happens always. No files attached.
Does this have something to do with SSL? Fetchmail seems to get the mail somehow, because it detects that there are unred messages. Then the error 500 shows up, and thus flushing fails.
Also, I found these other error coming from fetchmail’s log:
fetchmail: GSSAPI error gss_inquire_cred: Unspecified GSS failure. Minor code may provide more information
fetchmail: GSSAPI error gss_inquire_cred: No Kerberos credentials available (default cache: KEYRING:persistent:0)
fetchmail: No suitable GSSAPI credentials found. Skipping GSSAPI authentication.
fetchmail: If you want to use GSSAPI, you need credentials first, possibly from kinit.

Thank you very much for your feedback.

If you run Fetchmail manually with verbose logging enabled what do you see?

/usr/bin/fetchmail -v -v --fetchmailrc some_config_file

You can use --fetchlimit to only pull a single email for testing

I was exactly doing that, that is why I saw those error from fetchmail’s log. As I mentioned, it reaches the mail server, but then the error 500 shows up:
HTTP request failed: 500 Internal Server Error. Your webserver logs may have more information or there may be a network problem.
fetchmail: MDA returned nonzero status 75
not flushed
fetchmail: IMAP> A0009 LOGOUT

There is only one mail in the mailbox at the time of testing.

There should be more verbose logging.

Looking through the forum it looks like you may need to add

<Location /rt/REST/1.0/NoAuth>
      Order Allow,Deny
      Allow from all

To your fcgid apache config.

You also had the Kerberos warnings, could that be interfering with connecting the RT REST interface?

I did follow your instructions, but checking on past installations I realised that I got it to work using sendmail instead of msmtp for outgoing mail. msmtp seemed to be not working, so I removed it from RT configuration. Then I checked back fetchmail and now tickets are created and mail is flushed correctly.
This means that I have to dig now on how to set outgoing mail through an SMTP server, but at least, incoming mail is now working. Error 500 disappeared.
Thank you very much for your help.