From c95f0a64e5189ad1240fc547fcd774fe60f414a2 Mon Sep 17 00:00:00 2001 From: Stefan Strigler Date: Fri, 22 May 2015 11:11:36 +0200 Subject: introduce odbc port_timeout This introduces a new application environment variable 'port_timeout' that lets you set a custom timeout for ODBC when connecting to the port drivers upon initialization within odbc:connect/2. Default is still 5000 msec. --- lib/odbc/src/odbc.erl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/odbc/src/odbc.erl b/lib/odbc/src/odbc.erl index 4901821e9c..12560bfb6e 100644 --- a/lib/odbc/src/odbc.erl +++ b/lib/odbc/src/odbc.erl @@ -26,6 +26,8 @@ -include("odbc_internal.hrl"). +-define(ODBC_PORT_TIMEOUT, 5000). + %% API -------------------------------------------------------------------- -export([start/0, start/1, stop/0, @@ -523,10 +525,10 @@ handle_msg({connect, ODBCCmd, AutoCommitMode, SrollableCursors}, NewState = State#state{auto_commit_mode = AutoCommitMode, scrollable_cursors = SrollableCursors}, - case gen_tcp:accept(ListenSocketSup, 5000) of + case gen_tcp:accept(ListenSocketSup, port_timeout()) of {ok, SupSocket} -> gen_tcp:close(ListenSocketSup), - case gen_tcp:accept(ListenSocketOdbc, 5000) of + case gen_tcp:accept(ListenSocketOdbc, port_timeout()) of {ok, OdbcSocket} -> gen_tcp:close(ListenSocketOdbc), odbc_send(OdbcSocket, ODBCCmd), @@ -983,3 +985,6 @@ string_terminate_value(Binary) when is_binary(Binary) -> <>; string_terminate_value(null) -> null. + +port_timeout() -> + application:get_env(?MODULE, port_timeout, ?ODBC_PORT_TIMEOUT). -- cgit v1.2.3 From 1aab177fecf6784769cf7f44e8e8d3f7ca908d44 Mon Sep 17 00:00:00 2001 From: Stefan Strigler Date: Thu, 2 Jul 2015 14:07:31 +0200 Subject: add doc for odbc port_timeout --- lib/odbc/doc/src/odbc.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/odbc/doc/src/odbc.xml b/lib/odbc/doc/src/odbc.xml index 01bc0cb7ff..6a2a3587e4 100644 --- a/lib/odbc/doc/src/odbc.xml +++ b/lib/odbc/doc/src/odbc.xml @@ -221,6 +221,18 @@ and their meanings are dependent on the database being used. Reason is as per the Reason field when extended errors are not enabled. + + +

The current implementation spawns a port programm + written in C that utilizes the actual ODBC driver. There + is a default timeout of 5000 msec for this port programm + to connect to the Erlang ODBC application. This timeout + can be changed by setting an application specific + environment variable 'port_timeout' with the number of + milliseconds for the ODBC application. E.g.: [{odbc, + [{port_timeout, 60000}]}] to set it to 60 seconds. +

+
-- cgit v1.2.3 From 40a02d4e75e088b31df8e25973bd741ae0c39797 Mon Sep 17 00:00:00 2001 From: Stefan Strigler Date: Thu, 2 Jul 2015 14:07:45 +0200 Subject: add test for odbc port_timeout --- lib/odbc/test/odbc_connect_SUITE.erl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/odbc/test/odbc_connect_SUITE.erl b/lib/odbc/test/odbc_connect_SUITE.erl index 93e949faf6..2d4173a008 100644 --- a/lib/odbc/test/odbc_connect_SUITE.erl +++ b/lib/odbc/test/odbc_connect_SUITE.erl @@ -120,7 +120,16 @@ end_per_suite(_Config) -> %% Note: This function is free to add any key/value pairs to the Config %% variable, but should NOT alter/remove any existing entries. %%-------------------------------------------------------------------- +init_per_testcase(connect_port_timeout, Config) -> + odbc:stop(), + application:load(odbc), + application:set_env(odbc, port_timeout, 0), + odbc:start(), + init_per_testcase_common(Config); init_per_testcase(_TestCase, Config) -> + init_per_testcase_common(Config). + +init_per_testcase_common(Config) -> test_server:format("ODBCINI = ~p~n", [os:getenv("ODBCINI")]), Dog = test_server:timetrap(?default_timeout), Temp = lists:keydelete(connection_ref, 1, Config), @@ -135,7 +144,16 @@ init_per_testcase(_TestCase, Config) -> %% A list of key/value pairs, holding the test case configuration. %% Description: Cleanup after each test case %%-------------------------------------------------------------------- + +end_per_testcase(connect_port_timeout, Config) -> + application:unset_env(odbc, port_timeout), + odbc:stop(), + odbc:start(), + end_per_testcase_common(Config); end_per_testcase(_TestCase, Config) -> + end_per_testcase_common(Config). + +end_per_testcase_common(Config) -> Table = ?config(tableName, Config), {ok, Ref} = odbc:connect(?RDBMS:connection_string(), odbc_test_lib:platform_options()), Result = odbc:sql_query(Ref, "DROP TABLE " ++ Table), @@ -423,6 +441,18 @@ connect_timeout(Config) when is_list(Config) -> %% Need to return ok here "{'EXIT',timeout} return value" will %% be interpreted as that the testcase has timed out. ok. + +%%------------------------------------------------------------------------- +connect_port_timeout(doc) -> + ["Test the timeout for the port program to connect back to the odbc " + "application within the connect function."]; +connect_port_timeout(suite) -> []; +connect_port_timeout(Config) when is_list(Config) -> + %% Application environment var 'port_timeout' has been set to 0 by + %% init_per_testcase/2. + {error,timeout} = odbc:connect(?RDBMS:connection_string(), + odbc_test_lib:platform_options()). + %%------------------------------------------------------------------------- timeout(doc) -> ["Test that timeouts don't cause unwanted behavior sush as receiving" -- cgit v1.2.3