Skip to content

Commit

Permalink
Check lower limit for memory_limit setting
Browse files Browse the repository at this point in the history
Docker does not allow a limit below 6MB, which results in internal errors if people try to use one that low anyway.
  • Loading branch information
chvp committed Mar 21, 2023
1 parent 39fd61f commit 9d907b5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions app/models/exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,23 @@ def last_submission!(user, deadline = nil, course = nil)

def check_memory_limit
return unless ok?
return unless merged_config.fetch('evaluation', {}).fetch('memory_limit', 0) > 500_000_000 # 500MB

c = config
c['evaluation'] ||= {}
c['evaluation']['memory_limit'] = 500_000_000
store_config(c, "lowered memory limit for #{name}\n\nThe workers running the student's code only have 4 GB of memory " \
"and can run 6 students' code at the same time. The maximum memory limit is 500 MB so that if 6 students submit " \
'bad code at the same time, there is still 1 GB of memory left for Dodona itself and the operating system.')

limit = merged_config.fetch('evaluation', {}).fetch('memory_limit', nil)
return if limit.nil?

if limit > 500_000_000 # 500MB
c = config
c['evaluation'] ||= {}
c['evaluation']['memory_limit'] = 500_000_000
store_config(c, "lowered memory limit for #{name}\n\nThe workers running the student's code only have 4 GB of memory " \
"and can run 6 students' code at the same time. The maximum memory limit is 500 MB so that if 6 students submit " \
'bad code at the same time, there is still 1 GB of memory left for Dodona itself and the operating system.')
elsif limit < 6_000_000 # 6 MB
c = config
c['evaluation'] ||= {}
c['evaluation']['memory_limit'] = 10_000_000 # 10 MB
store_config(c, "raised memory limit for #{name}\n\nThe underlying system used to evaluate submissions does not allow a memory limity lower than 6MB.")
end
end

def self.move_relations(from, to)
Expand Down

0 comments on commit 9d907b5

Please sign in to comment.