Bug #70467 6.8.3: pooling disabled when using new ReplicationManager
Submitted: 30 Sep 2013 11:25 Modified: 25 May 2016 12:24
Reporter: Moshe Lampert Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.7.4, 6.8.3 OS:Windows (7, 2008 R2)
Assigned to: CPU Architecture:Any
Tags: pooling, replication

[30 Sep 2013 11:25] Moshe Lampert
Description:
I will try to create a testcase, but my problem goes on and off, so I can't repeat it in a simple way.

when I am using a 1-2 connections, it works.

I am using  6.7.4 and using a stress tool to simulate large usage of connections.

1. Pooling

server=master.sql.local;user id=; password=; database=; pooling=true ;Connection reset=false;  Min Pool Size=2;Max Pool Size=20;Character Set=utf8;Use Affected Rows=true; Connection Lifetime=10; UseAffectedRows=true; Connect Timeout=1;default command timeout=3;

I am using lifetime of 10 for this test. after a while I can see  in `select * from information_schema.processlist` large list of abandoned connections, with a large TIME.

I need connection pooling, but for the next step I was disabeld it.

after a while (600 open/close/standard use of my old and well-tested code), I can see this error message:

System.ArgumentOutOfRangeException	{"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"}	System.ArgumentOutOfRangeException

   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at MySql.Data.MySqlClient.Replication.ReplicationRoundRobinServerGroup.GetServer(Boolean isMaster)
   at MySql.Data.MySqlClient.Replication.ReplicationManager.GetNewConnection(String groupName, Boolean master, MySqlConnection connection)
   at MyCode

when I recived this error message I was looked in

MySql.Data.MySqlClient.Replication.ReplicationManager.Groups(0).Servers
three servers, three available , one is master and the 2 is slaves (as needed).

I need to stop/restart my program (or restart IIS to bypass this error messages)

How to repeat:
' one time
Dim oRep = MySql.Data.MySqlClient.Replication.ReplicationManager.AddGroup("testcase", "MySql.Data.MySqlClient.Replication.ReplicationRoundRobinServerGroup", 60)
oRep.AddServer("master.sql.local", True, s)
oRep.AddServer("slave1.sql.local", False, s)
oRep.AddServer("slave2.sql.local", False, s)

' every open
Dim c = New MySqlConnection()
MySql.Data.MySqlClient.Replication.ReplicationManager.GetNewConnection("a7", True , c) ' or false - ReadOnly or not

....
c.Close()
c.Dispose()
(open, close, use for a while, minimum 10K  commands)
[30 Sep 2013 11:26] Moshe Lampert
update to critical (on production this version is usless)
added OSses (7, r2)
[27 Nov 2013 0:38] Roberto Ezequiel Garcia Ballesteros
Hi Moshe,

I think the problem can be that you're using the methods directly. Please try to use replication as described in this post and let us know if this works:

https://blogs.oracle.com/MySqlOnWindows/entry/how_to_using_replication_load

Regards,
Roberto
[27 Nov 2013 20:20] Moshe Lampert
the problem is here again, here is the testcase:

<?xml version="1.0"?>
<configuration>
	<configSections>
		<section name="MySQL" type="MySql.Data.MySqlClient.MySqlConfiguration, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
	</configSections>
	<MySQL>
		<Replication>
			<ServerGroups>
				<Group name="MasterSlave">
					<Servers>
						<Server name="master" IsMaster="true" connectionstring="server=;user id=; password=; database=a7; pooling=true ;Connection reset=false;  Min Pool Size=2;Max Pool Size=60;Character Set=utf8; Connection Lifetime=0; UseAffectedRows=true; Connect Timeout=1;default command timeout=45;"/>
						<Server name="slave" IsMaster="false" connectionstring="server=;user id=; password=; database=a7; pooling=true ;Connection reset=false;  Min Pool Size=2;Max Pool Size=60;Character Set=utf8; Connection Lifetime=0; UseAffectedRows=true; Connect Timeout=6;default command timeout=45;"/>
					</Servers>
				</Group>
			</ServerGroups>
		</Replication>
	</MySQL>
	<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

Module Module1

	Sub Main()

		Dim lTasks As New List(Of task)
		For i = 0 To 1000 Step 1
			Dim t As Task = New Task(AddressOf DoTask)
			lTasks.Add(t)
			t.Start()
		Next

		Console.WriteLine("starting tasks...")
		Task.WaitAll(lTasks.ToArray())
	End Sub

	Sub DoTask()
		Console.WriteLine("begin task")
		Using Conn As New MySqlConnection("server=MasterSlave;database=db;")
			Conn.Open()
			Console.WriteLine("connected, database:" & Conn.Database)
			Thread.Sleep(1000)
			Conn.ChangeDatabase("db2")
			Console.WriteLine("connected, change:" & Conn.Database)

			Conn.ChangeDatabase("db")
			Dim Cmd = Conn.CreateCommand()
			Cmd.CommandText = "select * from table where pkid=1 limit 1"
			Using oReader = Cmd.ExecuteReader()
				oReader.Read()
				Console.Write(oReader("test") = "test text")
			End Using
		End Using

	End Sub

End Module

I tried a one task - works
tried a two tasks (for i=0 to 1) - first works, second fail.
[21 Jan 2014 20:05] Moshe Lampert
I retried the testcase with 6.8.3, and after some other tests I need to update the bug:

XML:

<MySQL>
		<Replication>
			<ServerGroups>
				<Group name="ConnString" retryTime="5">
					<Servers>
						<Server name="master" IsMaster="true" connectionstring="server=master;user id=; password=;database=; pooling=true ;"/>
						<Server name="slave" IsMaster="false" connectionstring="server=slave;user id=; password=;database=; pooling=true ;"/"/>
					</Servers>
				</Group>
			</ServerGroups>
		</Replication>
	</MySQL>

Test:

Sub Main()

		Dim lTasks As New List(Of task)
		For i = 0 To 500 Step 1
			Dim t As Task = New Task(AddressOf DoTask)
			lTasks.Add(t)
			t.Start()
		Next

		Console.WriteLine("starting tasks...")
		Task.WaitAll(lTasks.ToArray())

		Console.Read()
	End Sub

	Sub DoTask()
		Console.WriteLine("begin task")

' I can use MySql.Data.MySqlClient.Replication.ReplicationManager.GetNewConnection("ConnString", False, Conn), same problem

		Using Conn As New MySqlConnection("server=ConnString")
			Conn.Open()
			
			Thread.Sleep(1000)

			Console.WriteLine(Conn.ServerThread)
			Conn.Close()
		End Using

	End Sub

6.7.4: connector lost pooled connections, and connections just waste client/server memory.

6.8.3: pooling disabled at all (ServerThread is always a new one).
when I change connectionstring to a regular one without ReplicationManager, pooling return to work and I can see the numbers repeat itself.
[7 Oct 2014 7:33] Moshe Lampert
something new related to this problem?
[25 May 2016 12:03] Chiranjeevi Battula
Hello Moshe Lampert,

Thank you for the bug report.
This is most likely duplicate of Bug #77311, please see Bug #77311.

Thanks,
Chiranjeevi.
[25 May 2016 12:24] Moshe Lampert
it can be the same problem from other aspect, but I opened this bug  2 years before...