ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:81661] [Ruby trunk Bug#13654] irb save-history extension is not concurrency-safe
       [not found] <redmine.issue-13654.20170613131709@ruby-lang.org>
@ 2017-06-13 13:17 ` charles.cooke
  2017-07-14  9:28 ` [ruby-core:82064] [Ruby trunk Bug#13654][Assigned] " naruse
  1 sibling, 0 replies; 2+ messages in thread
From: charles.cooke @ 2017-06-13 13:17 UTC (permalink / raw)
  To: ruby-core

Issue #13654 has been reported by charles.cooke (Charles Cooke).

----------------------------------------
Bug #13654: irb save-history extension is not concurrency-safe
https://bugs.ruby-lang.org/issues/13654

* Author: charles.cooke (Charles Cooke)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------

## Issue
If 2 simultaneous irb sessions are running with save-history enabled, the history will be overwritten in full by the last irb session to exit and history will be lost.

The save-history extension currently loads the existing file on session start, maintains history throughout the session, then regenerates the history file with the preloaded + new history from the current session.  Therefore if the file contents are changed while the irb session is running, those changes are not overwritten when the session exits.

As many systems have logrotate and could manage the file buffering independently, one idea would be to just append the history from current session, rather than recreating the history file.

## Steps to reproduce
1.  Enable the save-history extension to log to a file
1.  Start an irb session (Session #1)
1.  Start a second irb session (Session #2)
1.  In Session #1, execute commands and exit - verify that the output is generated correctly
1.  In Session #2, execute commands and exit - PROBLEM - the output from Session #1 has been deleted

See output below:

~~~
[current]$ cat .irbrc
require 'irb/ext/save-history'

IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = File.join(Dir.pwd, 'log', 'irb.log')

==== START SESSION #1# ====
[current]$ irb
irb(main):001:0> puts 'Session #1 - Output'
Session #1 - Output
=> nil
irb(main):002:0>
[1]+  Stopped                 irb
==== BACKGROUND SESSION #1# ====

==== START SESSION #2# ====
[current]$ irb
irb(main):001:0> puts 'Session #2 - Output'
Session #2 - Output
=> nil
irb(main):002:0> exit
==== STOP SESSION #2# ====

==== OUTPUT IS EXPECTED ====
[current]$ cat log/irb.log
puts 'Session #2 - Output'
exit

==== RESUME SESSION #1 ====
[current]$ fg

irb(main):003:0* puts 'Session #1 - Overwrites everything'
Session #1 - Overwrites everything
=> nil
irb(main):004:0> exit

==== PROBLEM - OUTPUT FROM SESSION #1 ONLY ====
[current]$ cat log/irb.log
puts 'Session #1 - Output'
puts 'Session #1 - Overwrites everything'
exit
~~~



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:82064] [Ruby trunk Bug#13654][Assigned] irb save-history extension is not concurrency-safe
       [not found] <redmine.issue-13654.20170613131709@ruby-lang.org>
  2017-06-13 13:17 ` [ruby-core:81661] [Ruby trunk Bug#13654] irb save-history extension is not concurrency-safe charles.cooke
@ 2017-07-14  9:28 ` naruse
  1 sibling, 0 replies; 2+ messages in thread
From: naruse @ 2017-07-14  9:28 UTC (permalink / raw)
  To: ruby-core

Issue #13654 has been updated by naruse (Yui NARUSE).

Status changed from Open to Assigned
Assignee set to keiju (Keiju Ishitsuka)

----------------------------------------
Bug #13654: irb save-history extension is not concurrency-safe
https://bugs.ruby-lang.org/issues/13654#change-65798

* Author: charles.cooke (Charles Cooke)
* Status: Assigned
* Priority: Normal
* Assignee: keiju (Keiju Ishitsuka)
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------

## Issue
If 2 simultaneous irb sessions are running with save-history enabled, the history will be overwritten in full by the last irb session to exit and history will be lost.

The save-history extension currently loads the existing file on session start, maintains history throughout the session, then regenerates the history file with the preloaded + new history from the current session.  Therefore if the file contents are changed while the irb session is running, those changes are not overwritten when the session exits.

As many systems have logrotate and could manage the file buffering independently, one idea would be to just append the history from current session, rather than recreating the history file.

## Steps to reproduce
1.  Enable the save-history extension to log to a file
1.  Start an irb session (Session #1)
1.  Start a second irb session (Session #2)
1.  In Session #1, execute commands and exit - verify that the output is generated correctly
1.  In Session #2, execute commands and exit - PROBLEM - the output from Session #1 has been deleted

See output below:

~~~
[current]$ cat .irbrc
require 'irb/ext/save-history'

IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = File.join(Dir.pwd, 'log', 'irb.log')

==== START SESSION #1# ====
[current]$ irb
irb(main):001:0> puts 'Session #1 - Output'
Session #1 - Output
=> nil
irb(main):002:0>
[1]+  Stopped                 irb
==== BACKGROUND SESSION #1# ====

==== START SESSION #2# ====
[current]$ irb
irb(main):001:0> puts 'Session #2 - Output'
Session #2 - Output
=> nil
irb(main):002:0> exit
==== STOP SESSION #2# ====

==== OUTPUT IS EXPECTED ====
[current]$ cat log/irb.log
puts 'Session #2 - Output'
exit

==== RESUME SESSION #1 ====
[current]$ fg

irb(main):003:0* puts 'Session #1 - Overwrites everything'
Session #1 - Overwrites everything
=> nil
irb(main):004:0> exit

==== PROBLEM - OUTPUT FROM SESSION #1 ONLY ====
[current]$ cat log/irb.log
puts 'Session #1 - Output'
puts 'Session #1 - Overwrites everything'
exit
~~~



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-14  9:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-13654.20170613131709@ruby-lang.org>
2017-06-13 13:17 ` [ruby-core:81661] [Ruby trunk Bug#13654] irb save-history extension is not concurrency-safe charles.cooke
2017-07-14  9:28 ` [ruby-core:82064] [Ruby trunk Bug#13654][Assigned] " naruse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).