Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixlib::ShellOut::CommandTimeout error after 600 seconds of SQL query #322

Open
asper-ru opened this issue Nov 3, 2020 · 2 comments
Open
Labels
Feature Request Enhancement to existing functionality or new functionality

Comments

@asper-ru
Copy link

asper-ru commented Nov 3, 2020

I tried to make long SQL query (loading database), but it terminated after 10 minutes due to Mixlib::ShellOut timeout settings.

Cookbook version 4.1.0
Version of chef-client in your environment: 16.1.16
Operating system distribution and release version: Ubuntu 20.04

Steps to reproduce the behavior:

To run a long SQL command, to load database from the file, for example. In my case it was:

mariadb_database 'load database' do
sql 'use db_staging; source /var/lib/db_production.sql;'
action :query
end

It starting to load the database, but after ten minutes fails with an error:

Caused by Mixlib::ShellOut::CommandTimeout: Command timed out after 600s:
Command exceeded allowed execution time, process terminated

I guess it can be related with mixlib-shellout gem settings, where I can find the line:

DEFAULT_READ_TIMEOUT = 600

(the file in my system is: /opt/chef/embedded/lib/ruby/gems/2.7.0/gems/mixlib-shellout-3.0.9/lib/mixlib/shellout.rb)

But I have no idea how to redefine this constant from my recipe to let chef-client work longer

@ramereth
Copy link
Contributor

ramereth commented Nov 4, 2020

@asper-ru shell_out exposes a timeout parameter which will override the constant if set. Ideally we'd add some logic here:

#######
# Function to execute an SQL statement in the default database.
# Input: Query could be a single String or an Array of String.
# Output: A String with <TAB>-separated columns and \n-separated rows.
# This is easiest for 1-field (1-row, 1-col) results, otherwise
# it will be complex to parse the results.
def execute_sql(query, db_name, ctrl)
cmd = shell_out(sql_command_string(query, db_name, ctrl),
user: 'root')
if cmd.exitstatus != 0
Chef::Log.fatal("mysql failed executing this SQL statement:\n#{query}")
Chef::Log.fatal(cmd.stderr)
raise 'SQL ERROR'
end
cmd.stdout
end

To set the timeout and then add new a new timeout property to resources which use this method.

@ramereth ramereth added the Feature Request Enhancement to existing functionality or new functionality label Nov 4, 2020
@asper-ru
Copy link
Author

Well, using resource 'execute' with 'timeout' property is an option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Enhancement to existing functionality or new functionality
Projects
None yet
Development

No branches or pull requests

2 participants