Ticket #4512 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

EventLog does not play well with forkProcess

Reported by: adept Owned by: simonmar
Priority: high Milestone: 7.0.2
Component: Runtime System Version: 7.0.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I am trying to see an eventlog of process that daemonizes itself via forkProcess.

Unfortunately, as parent process dies, he writes out his eventlog (or at least a header part, I haven't checked exactly), and eventlog of the child process is then appended to the same file.

As a result, neither ghc-events nor threadscope is able to read the eventlog file.

I've modified the program so that it would not fork, and generated "good" eventlog. I'm attaching it and "bad" eventlog as well so you can see the difference by yourself.

Perhaps "+RTS -ls" could write output to filename that includes the PID of the process, like "program.$PID.eventlog"?

Attachments

good.eventlog Download (2.0 KB) - added by adept 3 years ago.
Good eventlog from modified version of the program that does not fork
bad.eventlog Download (3.9 KB) - added by adept 3 years ago.
Bad eventlog from the version that uses forkProcess
4512.bundle Download (13.9 KB) - added by adept 2 years ago.
Reopening eventlog after fork()

Change History

Changed 3 years ago by adept

Good eventlog from modified version of the program that does not fork

Changed 3 years ago by adept

Bad eventlog from the version that uses forkProcess

  Changed 2 years ago by igloo

  • priority changed from normal to high
  • milestone set to 7.0.2

  Changed 2 years ago by adept

  • owner set to adept

Well, here is a plan: when forked child process does initEventLogging, it should detect that prog_name.evenlog is already opened and being written to by another process.

It could be done with: 1)OS locks 2)file-based locking (*.pid files or something similar) 3)using "static int alreadyWriting", which would be populated by parent process.

I'm inclined to go with (3). Forked child will check to see whether parent process is alreadyWriting and will use different filename if necessary.

Comments?

follow-up: ↓ 4   Changed 2 years ago by adept

  • status changed from new to patch

Attached patch fixes the problem. Please review.

Changed 2 years ago by adept

Reopening eventlog after fork()

in reply to: ↑ 3   Changed 2 years ago by simonmar

  • owner changed from adept to simonmar

Replying to adept:

Attached patch fixes the problem. Please review.

Looks fine. I'll validate and push.

  Changed 2 years ago by simonmar

  • status changed from patch to merge

Thanks, pushed:

Fri Dec  3 13:39:50 GMT 2010  Dmitry Astapov <dastapov@gmail.com>
  * Fixes for #4512: EventLog.c - provides ability to terminate event logging, Schedule.c - uses them in forkProcess.

  Changed 2 years ago by simonmar

A couple more fixes were required to this patch:

Fri Dec 10 09:39:06 GMT 2010  Simon Marlow <marlowsd@gmail.com>
  * allocate enough room for the longer filename (addendum to #4512)

Fri Dec 10 09:39:51 GMT 2010  Simon Marlow <marlowsd@gmail.com>
  * Only reset the event log if logging is turned on (addendum to #4512)

  Changed 2 years ago by igloo

First merged.

  Changed 2 years ago by igloo

  • status changed from merge to closed
  • resolution set to fixed

Last 2 also merged.

Note: See TracTickets for help on using tickets.