Edgewall Software
Modify

Opened 8 years ago

Closed 8 years ago

#12525 closed defect (wontfix)

trac-admin hotcopy corrupts source database if stdout is closed

Reported by: simon.fayer05@… Owned by:
Priority: normal Milestone:
Component: admin/console Version: 1.0.10
Severity: minor Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Jun Omae)

While writing a backup script, I found that if I close stdout on the trac-admin hotcopy command, the source database gets partially overwritten with the usual output text (causing it to become corrupt).

A script to reproduce this is simply:

#!/bin/sh
trac-admin /path/to/myenv hotcopy /backups/trac >&-

(If you run it a second time, you should get OperationalError: unsupported file format due to the corrupt database).

My environment is standard CentOS7 with python 2.7.5.

I think this has appeared before in ticket #5222 (I didn't re-open that one as it was so old).

Attachments (0)

Change History (4)

comment:1 by simon.fayer05@…, 8 years ago

Description: modified (diff)

comment:2 by Jun Omae, 8 years ago

Description: modified (diff)

It is not reproduced with SQLite. What database are you using?

I think stdout shouldn't be closed even if it can be reproduced. Why? I think the stdout should be redirected to /dev/null if you don't need stdout.

comment:3 by simon.fayer05@…, 8 years ago

I am using SQLite, I tried it with the same trac version (1.0.10) on Fedora which doesn't show the issue.

Now I've had a more detailed look at it, I think I can see what's happening… Doing sys.stdout.write always writes to fd number 1, whatever file is open there. On my CentOS machine, that's the SQLite database during a hotcopy, but on Fedora fd 1 is closed and the database is number 3 (so nothing bad happens).

Yes, writing to /dev/null works fine, it was just surprising to find my database corrupt after running a backup the first time. In this instance the corruption is obvious as it happens to write over a bit of the database header, but there may be times when this happens elsewhere in the file and goes unnoticed.

Perhaps it would be possible to test if stdout or stderr are closed in the startup of trac-admin and print an error? That would at least prevent anyone getting caught out by this again.

comment:4 by Jun Omae, 8 years ago

Resolution: wontfix
Status: newclosed

If stdout and stderr are closed, error messages cannot be printed to stdout/stderr. Closing as wontfix.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The ticket will remain with no owner.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from (none) to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.