I had been seeing a lot - and I mean a lot - of watchdog notices on one of my sites as follows:

Warning: Cannot modify header information - headers already sent by (output started at [PATH]/includes/common.inc:2700) in drupal_send_headers() (line 1221 of [PATH]/includes/bootstrap.inc).

I tracked down one of the causes to comment_goodness. This module implements a hook_menu_alter() to put comment_goodness_permalink() in place of the comment handler. This is totally cool, save for how it handles comments-not-found situations.

In that case it calls: drupal_not_found() - which calls a page display and kicks off headers and all that goodness. The problem is - so does the menu handler! So now we have two page displays going out, both trying to set headers and boom - watchdog log message pops up because of the second set of headers going out after data has already been sent by the first call.

The fix is really really simple though!

Per direction at https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_... - instead of calling drupal_not_found(), simply return MENU_NOT_FOUND in the menu handler function.

CommentFileSizeAuthor
#1 comment_goodness-2218501.patch428 bytesBastlynn
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Bastlynn’s picture

FileSize
428 bytes

Patch attached

Bastlynn’s picture

Status: Active » Needs review
formatC'vt’s picture

Status: Needs review » Reviewed & tested by the community

yes, this patch fix this bug

  • Bastlynn authored a2dcb18 on 7.x-1.x
    Issue #2218501 by Bastlynn: Fixed Cannot modify header information...
jessebeach’s picture

Status: Reviewed & tested by the community » Fixed

Thanks Bastlynn and formatC'vt!

d12cb7d..a2dcb18

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

wfragakis’s picture

Old bug but took me forever to find this after much searching - this patch solved my watchdog notice:
Warning: Cannot modify header information - headers already sent by (output started at[PATH]/includes/common.inc:2791) in drupal_send_headers() (line 1503 of [PATH]/includes/bootstrap.inc).