trilogy 2.12.5 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb255b4a759f25f1ddbf289fb3d17e163cd4efa1dcdf0537d3c9bafeac7183ab
4
- data.tar.gz: 8d89ef7ec7d5a11cc480a3f6fc0c7ba96c4baa761dccb0b773b88cc382897ea8
3
+ metadata.gz: aa039c6b0e08712590ea5c50bea7c9a6418d56b1878b3c2935568248d0c5deb5
4
+ data.tar.gz: f76d5315bd82dd00a58c43d7de51885448ba3b72fb0e2adcca3fd132e4bd1163
5
5
  SHA512:
6
- metadata.gz: 14bd176ad7f6289bb38b42036344b94800831699b82807464f6ee124e7d31c9a17fa474cabf342ae0c8b549f664062aa0dd52b14e75b06c65c1ff717520e9fda
7
- data.tar.gz: 7928348c8d89a3e0a5ad5dec06503a9ba3111f0e4f33e4d1448a85407c614c98adbd3adbe4e2e6c763654747a1a484c7437c3cea6c853b448eb105335c8dfb78
6
+ metadata.gz: 45cb57bc1614f81b1f477e987936b00ba97ec75acd4b88d4e86640848442daa76993cb14fe6b39bccf76c3e7a5a1dc6f86c37d5af96e179c0889c9e50356cac9
7
+ data.tar.gz: 5da626807137fe79611a85157b4537fde0c7451c047074ddac514732ecfed04f0e665b9e432607aa52fb73830bad176dd6d640fb2ab87019b71e46a44fea3b52
data/README.md CHANGED
@@ -86,3 +86,5 @@ differences:
86
86
  the transcoding step up to the caller.
87
87
  * There is no `as` query option. Calling `Trilogy::Result#each` will yield an array
88
88
  of row values. If you want a hash you should use `Trilogy::Result#each_hash`.
89
+ * The default `connect_timeout` is 5 seconds, while mysql2 defaults to 120 seconds.
90
+ Pass `connect_timeout: nil` to disable the timeout.
@@ -431,6 +431,8 @@ static int _cb_ruby_wait(trilogy_sock_t *sock, trilogy_wait_t wait)
431
431
  int state = 0;
432
432
  rb_protect(rb_trilogy_wait_protected, (VALUE)&args, &state);
433
433
  if (state) {
434
+ struct trilogy_ctx *ctx = sock->opts.privdata;
435
+ rb_trilogy_release_buffer(ctx);
434
436
  trilogy_sock_shutdown(sock);
435
437
  rb_jump_tag(state);
436
438
  }
@@ -605,10 +607,24 @@ static int rb_io_descriptor(VALUE io)
605
607
  }
606
608
  #endif
607
609
 
610
+ static inline VALUE config_set_str(VALUE opts, ID key, char **member)
611
+ {
612
+ VALUE val = rb_hash_aref(opts, ID2SYM(key));
613
+ if (NIL_P(val)) {
614
+ return Qfalse;
615
+ }
616
+
617
+ Check_Type(val, T_STRING);
618
+ *member = StringValueCStr(val);
619
+ return val;
620
+ }
621
+
608
622
  static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VALUE charset, VALUE opts)
609
623
  {
610
624
  struct trilogy_ctx *ctx = get_ctx(self);
611
- trilogy_sockopt_t connopt = {0};
625
+ trilogy_sockopt_t connopt = {
626
+ .privdata = ctx,
627
+ };
612
628
  trilogy_handshake_t handshake;
613
629
  VALUE val;
614
630
 
@@ -658,10 +674,10 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VA
658
674
  connopt.max_allowed_packet = NUM2SIZET(val);
659
675
  }
660
676
 
661
- if ((val = rb_hash_lookup(opts, ID2SYM(id_host))) != Qnil) {
662
- Check_Type(val, T_STRING);
677
+ VALUE host = config_set_str(opts, id_host, &connopt.hostname);
678
+ VALUE path;
663
679
 
664
- connopt.hostname = StringValueCStr(val);
680
+ if (host) {
665
681
  connopt.port = 3306;
666
682
 
667
683
  if ((val = rb_hash_lookup(opts, ID2SYM(id_port))) != Qnil) {
@@ -671,26 +687,17 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VA
671
687
  } else {
672
688
  connopt.path = (char *)"/tmp/mysql.sock";
673
689
 
674
- if ((val = rb_hash_lookup(opts, ID2SYM(id_socket))) != Qnil) {
675
- Check_Type(val, T_STRING);
676
- connopt.path = StringValueCStr(val);
677
- }
678
- }
679
-
680
- if ((val = rb_hash_aref(opts, ID2SYM(id_username))) != Qnil) {
681
- Check_Type(val, T_STRING);
682
- connopt.username = StringValueCStr(val);
690
+ path = config_set_str(opts, id_socket, &connopt.path);
683
691
  }
684
692
 
685
- if ((val = rb_hash_aref(opts, ID2SYM(id_password))) != Qnil) {
686
- Check_Type(val, T_STRING);
687
- connopt.password = RSTRING_PTR(val);
688
- connopt.password_len = RSTRING_LEN(val);
693
+ VALUE username = config_set_str(opts, id_username, &connopt.username);
694
+ VALUE password = config_set_str(opts, id_password, &connopt.password);
695
+ if (password) {
696
+ connopt.password_len = RSTRING_LEN(password);
689
697
  }
690
698
 
691
- if ((val = rb_hash_aref(opts, ID2SYM(id_database))) != Qnil) {
692
- Check_Type(val, T_STRING);
693
- connopt.database = StringValueCStr(val);
699
+ VALUE database = config_set_str(opts, id_database, &connopt.database);
700
+ if (database) {
694
701
  connopt.flags |= TRILOGY_CAPABILITIES_CONNECT_WITH_DB;
695
702
  }
696
703
 
@@ -710,45 +717,14 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VA
710
717
  connopt.flags |= TRILOGY_CAPABILITIES_MULTI_STATEMENTS;
711
718
  }
712
719
 
713
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_ca))) != Qnil) {
714
- Check_Type(val, T_STRING);
715
- connopt.ssl_ca = StringValueCStr(val);
716
- }
717
-
718
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_capath))) != Qnil) {
719
- Check_Type(val, T_STRING);
720
- connopt.ssl_capath = StringValueCStr(val);
721
- }
722
-
723
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_cert))) != Qnil) {
724
- Check_Type(val, T_STRING);
725
- connopt.ssl_cert = StringValueCStr(val);
726
- }
727
-
728
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_cipher))) != Qnil) {
729
- Check_Type(val, T_STRING);
730
- connopt.ssl_cipher = StringValueCStr(val);
731
- }
732
-
733
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_crl))) != Qnil) {
734
- Check_Type(val, T_STRING);
735
- connopt.ssl_crl = StringValueCStr(val);
736
- }
737
-
738
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_crlpath))) != Qnil) {
739
- Check_Type(val, T_STRING);
740
- connopt.ssl_crlpath = StringValueCStr(val);
741
- }
742
-
743
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_key))) != Qnil) {
744
- Check_Type(val, T_STRING);
745
- connopt.ssl_key = StringValueCStr(val);
746
- }
747
-
748
- if ((val = rb_hash_aref(opts, ID2SYM(id_tls_ciphersuites))) != Qnil) {
749
- Check_Type(val, T_STRING);
750
- connopt.tls_ciphersuites = StringValueCStr(val);
751
- }
720
+ VALUE ssl_ca = config_set_str(opts, id_ssl_ca, &connopt.ssl_ca);
721
+ VALUE ssl_capath = config_set_str(opts, id_ssl_capath, &connopt.ssl_capath);
722
+ VALUE ssl_cert = config_set_str(opts, id_ssl_cert, &connopt.ssl_cert);
723
+ VALUE ssl_cipher = config_set_str(opts, id_ssl_cipher, &connopt.ssl_cipher);
724
+ VALUE ssl_crl = config_set_str(opts, id_ssl_crl, &connopt.ssl_crl);
725
+ VALUE ssl_crlpath = config_set_str(opts, id_ssl_crlpath, &connopt.ssl_crlpath);
726
+ VALUE ssl_key = config_set_str(opts, id_ssl_key, &connopt.ssl_key);
727
+ VALUE tls_ciphersuites = config_set_str(opts, id_tls_ciphersuites, &connopt.tls_ciphersuites);
752
728
 
753
729
  if ((val = rb_hash_aref(opts, ID2SYM(id_tls_min_version))) != Qnil) {
754
730
  Check_Type(val, T_FIXNUM);
@@ -787,6 +763,21 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VA
787
763
 
788
764
  rb_trilogy_release_buffer(ctx);
789
765
 
766
+ // Ensure all our strings are pinned.
767
+ RB_GC_GUARD(host);
768
+ RB_GC_GUARD(username);
769
+ RB_GC_GUARD(password);
770
+ RB_GC_GUARD(path);
771
+ RB_GC_GUARD(database);
772
+ RB_GC_GUARD(ssl_ca);
773
+ RB_GC_GUARD(ssl_capath);
774
+ RB_GC_GUARD(ssl_cert);
775
+ RB_GC_GUARD(ssl_cipher);
776
+ RB_GC_GUARD(ssl_crl);
777
+ RB_GC_GUARD(ssl_crlpath);
778
+ RB_GC_GUARD(ssl_key);
779
+ RB_GC_GUARD(tls_ciphersuites);
780
+
790
781
  return Qnil;
791
782
  }
792
783
 
@@ -795,6 +786,7 @@ static VALUE rb_trilogy_change_db(VALUE self, VALUE database)
795
786
  struct trilogy_ctx *ctx = get_open_ctx(self);
796
787
 
797
788
  StringValue(database);
789
+ database = rb_str_new_frozen(database);
798
790
 
799
791
  rb_trilogy_acquire_buffer(ctx);
800
792
 
@@ -826,6 +818,7 @@ static VALUE rb_trilogy_change_db(VALUE self, VALUE database)
826
818
  }
827
819
 
828
820
  rb_trilogy_release_buffer(ctx);
821
+ RB_GC_GUARD(database);
829
822
 
830
823
  return Qtrue;
831
824
  }
@@ -1065,6 +1058,7 @@ static VALUE execute_read_query_response(struct trilogy_ctx *ctx)
1065
1058
 
1066
1059
  // If we have seen an unexpected exception, jump to it so it gets raised.
1067
1060
  if (state) {
1061
+ rb_trilogy_release_buffer(ctx);
1068
1062
  trilogy_sock_shutdown(ctx->conn.socket);
1069
1063
  rb_jump_tag(state);
1070
1064
  }
@@ -1135,6 +1129,7 @@ static VALUE rb_trilogy_query(VALUE self, VALUE query)
1135
1129
 
1136
1130
  StringValue(query);
1137
1131
  query = rb_str_export_to_enc(query, ctx->encoding);
1132
+ query = rb_str_new_frozen(query);
1138
1133
 
1139
1134
  rb_trilogy_acquire_buffer(ctx);
1140
1135
 
@@ -1148,6 +1143,7 @@ static VALUE rb_trilogy_query(VALUE self, VALUE query)
1148
1143
  handle_trilogy_error(ctx, rc, "trilogy_query_send");
1149
1144
  }
1150
1145
 
1146
+ RB_GC_GUARD(query);
1151
1147
  return execute_read_query_response(ctx);
1152
1148
  }
1153
1149
 
@@ -1191,9 +1187,11 @@ static VALUE rb_trilogy_ping(VALUE self)
1191
1187
  static VALUE rb_trilogy_escape(VALUE self, VALUE str)
1192
1188
  {
1193
1189
  struct trilogy_ctx *ctx = get_open_ctx(self);
1194
- rb_encoding *str_enc = rb_enc_get(str);
1195
1190
 
1196
1191
  StringValue(str);
1192
+ str = rb_str_new_frozen(str);
1193
+
1194
+ rb_encoding *str_enc = rb_enc_get(str);
1197
1195
 
1198
1196
  if (!rb_enc_asciicompat(str_enc)) {
1199
1197
  rb_raise(rb_eEncCompatError, "input string must be ASCII-compatible");
@@ -1214,6 +1212,7 @@ static VALUE rb_trilogy_escape(VALUE self, VALUE str)
1214
1212
 
1215
1213
  rb_trilogy_release_buffer(ctx);
1216
1214
 
1215
+ RB_GC_GUARD(str);
1217
1216
  return escaped_string;
1218
1217
  }
1219
1218
 
@@ -237,7 +237,7 @@ int trilogy_stmt_bind_data(trilogy_conn_t *conn, trilogy_stmt_t *stmt, uint16_t
237
237
 
238
238
  /* trilogy_stmt_read_full_row - Read a row from the prepared statement execute response.
239
239
  *
240
- * This should only be called after a sucessful call to trilogy_stmt_execute.
240
+ * This should only be called after a successful call to trilogy_stmt_execute.
241
241
  * You should continue calling this until TRILOGY_EOF is returned. Denoting the end
242
242
  * of the result set.
243
243
  *
@@ -68,7 +68,7 @@ int trilogy_buffer_write(trilogy_buffer_t *buffer, const uint8_t *ptr, size_t le
68
68
 
69
69
  /* trilogy_buffer_free - Free an trilogy_buffer_t's underlying storage. The buffer
70
70
  * must be re-initialized with trilogy_buffer_init if it is to be reused. Any
71
- * operations performed on an unintialized or freed buffer are undefined.
71
+ * operations performed on an uninitialized or freed buffer are undefined.
72
72
  *
73
73
  * buffer - An initialized trilogy_buffer_t.
74
74
  */
@@ -607,7 +607,7 @@ void trilogy_free(trilogy_conn_t *conn);
607
607
  * conn - A pre-initialized trilogy_conn_t pointer.
608
608
  *
609
609
  * Return values:
610
- * TRILOGY_OK - The connection was successfuly discarded and freed.
610
+ * TRILOGY_OK - The connection was successfully discarded and freed.
611
611
  * TRILOGY_SYSERR - A system error occurred, check errno. The connection wasn't freed.
612
612
  */
613
613
  int trilogy_discard(trilogy_conn_t *conn);
@@ -665,7 +665,7 @@ int trilogy_stmt_prepare_recv(trilogy_conn_t *conn, trilogy_stmt_t *stmt_out);
665
665
 
666
666
  /* trilogy_stmt_bind_data_send - Send a prepared statement bind long data command to the server.
667
667
  *
668
- * There is no pairing `trilogy_stmt_bind_data_recv` fucntion to this one because the server
668
+ * There is no pairing `trilogy_stmt_bind_data_recv` function to this one because the server
669
669
  * doesn't send a response to this command.
670
670
  *
671
671
  * conn - A connected trilogy_conn_t pointer. Using a disconnected trilogy_conn_t is
@@ -734,7 +734,7 @@ int trilogy_stmt_execute_recv(trilogy_conn_t *conn, uint64_t *column_count_out);
734
734
 
735
735
  /* trilogy_stmt_read_row - Read a row from the prepared statement execute response.
736
736
  *
737
- * This should only be called after a sucessful call to trilogy_stmt_execute_recv.
737
+ * This should only be called after a successful call to trilogy_stmt_execute_recv.
738
738
  * You should continue calling this until TRILOGY_EOF is returned. Denoting the end
739
739
  * of the result set.
740
740
  *
@@ -809,7 +809,7 @@ int trilogy_stmt_reset_recv(trilogy_conn_t *conn);
809
809
 
810
810
  /* trilogy_stmt_close_send - Send a prepared statement close command to the server.
811
811
  *
812
- * There is no pairing `trilogy_stmt_close_recv` fucntion to this one because the server
812
+ * There is no pairing `trilogy_stmt_close_recv` function to this one because the server
813
813
  * doesn't send a response to this command.
814
814
  *
815
815
  * conn - A connected trilogy_conn_t pointer. Using a disconnected trilogy_conn_t is
@@ -317,7 +317,7 @@ typedef enum {
317
317
  /* The column is part of a primary key. \
318
318
  */ \
319
319
  XX(TRILOGY_COLUMN_FLAG_PRI_KEY, 0x2) \
320
- /* The column has the `UNIQUE` flag set. Requring all values to be unique. \
320
+ /* The column has the `UNIQUE` flag set. Requiring all values to be unique. \
321
321
  */ \
322
322
  XX(TRILOGY_COLUMN_FLAG_UNIQUE_KEY, 0x4) \
323
323
  /* The column is part of a key. \
@@ -889,7 +889,7 @@ int trilogy_parse_ok_packet(const uint8_t *buff, size_t len, uint32_t capabiliti
889
889
  /* trilogy_parse_eof_packet - Parse an EOF packet.
890
890
  *
891
891
  * buff - A pointer to the buffer containing the EOF packet data.
892
- * len - The lenght of buff in bytes.
892
+ * len - The length of buff in bytes.
893
893
  * capabilities - A bitmask of TRILOGY_CAPABILITIES_t flags.
894
894
  * out_packet - Out parameter; A pointer to a pre-allocated
895
895
  * trilogy_eof_packet_t.
@@ -72,6 +72,8 @@ typedef struct {
72
72
  TRILOGY_CAPABILITIES_t flags;
73
73
 
74
74
  size_t max_allowed_packet;
75
+
76
+ void *privdata;
75
77
  } trilogy_sockopt_t;
76
78
 
77
79
  typedef struct trilogy_sock_t {
@@ -567,7 +567,7 @@ int trilogy_build_auth_packet(trilogy_builder_t *builder, const char *user, cons
567
567
  }
568
568
 
569
569
  if (pass_len > 0) {
570
- // Fallback to te default unless we have SHA2 requested
570
+ // Fallback to the default unless we have SHA2 requested
571
571
  if (!strcmp("caching_sha2_password", auth_plugin)) {
572
572
  trilogy_pack_scramble_sha2_hash(scramble, pass, pass_len, auth_response, &auth_response_len);
573
573
  } else {
@@ -1,3 +1,3 @@
1
1
  class Trilogy
2
- VERSION = "2.12.5"
2
+ VERSION = "2.13.0"
3
3
  end
data/lib/trilogy.rb CHANGED
@@ -22,15 +22,22 @@ class Trilogy
22
22
  super
23
23
  end
24
24
 
25
+ NEVER = { Object => :never }.freeze
26
+ IMMEDIATE = { Object => :immediate }.freeze
27
+
25
28
  synchronized_methods = Trilogy.public_instance_methods(false) - %i(closed? server_version)
26
29
  source = synchronized_methods.flat_map do |method|
27
30
  [
28
31
  "def #{method}(...)",
29
- "raise SynchronizationError unless @mutex.try_lock",
30
- "begin",
31
- "super",
32
- "ensure",
33
- "@mutex.unlock",
32
+ "Thread.handle_interrupt(NEVER) do",
33
+ "raise SynchronizationError unless @mutex.try_lock",
34
+ "begin",
35
+ "Thread.handle_interrupt(IMMEDIATE) do",
36
+ "super",
37
+ "end",
38
+ "ensure",
39
+ "@mutex.unlock",
40
+ "end",
34
41
  "end",
35
42
  "end",
36
43
  ]
@@ -52,7 +59,7 @@ class Trilogy
52
59
  begin
53
60
  if host = options[:host]
54
61
  port = options[:port] || 3306
55
- connect_timeout = options[:connect_timeout] || options[:write_timeout]
62
+ connect_timeout = options.fetch(:connect_timeout, 5) || options[:write_timeout]
56
63
 
57
64
  socket = TCPSocket.new(host, port, connect_timeout: connect_timeout)
58
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trilogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.5
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Engineering
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 4.0.11
90
+ rubygems_version: 4.0.6
91
91
  specification_version: 4
92
92
  summary: A friendly MySQL-compatible library for Ruby, binding to libtrilogy
93
93
  test_files: []